Skip to content

Commit 4123506

Browse files
committed
Fixed test_no_ctypes not testing the right thing(s)
1 parent c344f42 commit 4123506

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

setuptools/tests/test_bdist_wheel.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import subprocess
1111
import sys
1212
import sysconfig
13+
from contextlib import suppress
1314
from functools import partial
1415
from inspect import cleandoc
1516
from unittest.mock import Mock
@@ -482,14 +483,16 @@ def _fake_import(name: str, *args, **kwargs):
482483

483484
return importlib.__import__(name, *args, **kwargs)
484485

486+
with suppress(KeyError):
487+
monkeypatch.delitem(sys.modules, "setuptools.extern.wheel.macosx_libfile")
488+
485489
# Install an importer shim that refuses to load ctypes
486490
monkeypatch.setattr(builtins, "__import__", _fake_import)
491+
with pytest.raises(ModuleNotFoundError, match="No module named ctypes"):
492+
import setuptools.extern.wheel.macosx_libfile
487493

488-
# Unload all wheel modules
489-
for module in list(sys.modules):
490-
if module.startswith("wheel"):
491-
monkeypatch.delitem(sys.modules, module)
492-
493-
from setuptools.command import bdist_wheel
494+
# Unload and reimport the bdist_wheel command module to make sure it won't try to
495+
# import ctypes
496+
monkeypatch.delitem(sys.modules, "setuptools.command.bdist_wheel")
494497

495-
assert bdist_wheel
498+
import setuptools.command.bdist_wheel # noqa: F401

0 commit comments

Comments
 (0)