Skip to content

Commit

Permalink
don't rely on imports to test cython_ext
Browse files Browse the repository at this point in the history
direct importlib is easier
  • Loading branch information
minrk committed May 25, 2024
1 parent b8807b9 commit 63c7849
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions tests/test_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,19 @@
)
@pytest.mark.parametrize('language_level', [3, 2])
def test_cython(language_level, request, tmpdir):
assert 'zmq.tests.cython_ext' not in sys.modules

importers = pyximport.install(
hook = pyximport.install(
setup_args=dict(include_dirs=zmq.get_includes()),
language_level=language_level,
build_dir=str(tmpdir),
)

cython_ext = None

def unimport():
pyximport.uninstall(*importers)
sys.modules.pop('zmq.tests.cython_ext', None)

request.addfinalizer(unimport)

# this import tests the compilation
from zmq_test_utils import cython_ext
# don't actually need the hook, just the finder
pyximport.uninstall(*hook)
finder = hook[1]

# loading the module tests the compilation
spec = finder.find_spec("cython_ext", [HERE])
cython_ext = spec.loader.create_module(spec)
spec.loader.exec_module(cython_ext)

assert hasattr(cython_ext, 'send_recv_test')

Expand Down

0 comments on commit 63c7849

Please sign in to comment.