Skip to content

Commit 4b923bb

Browse files
committed
Merge pull request apache#395 from datastax/398
PYTHON-398 - Only have pyximport installed while importing test modules
2 parents 85a99f8 + 5f4d205 commit 4b923bb

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

tests/unit/cython/utils.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
from cassandra.cython_deps import HAVE_CYTHON, HAVE_NUMPY
1616

17-
if HAVE_CYTHON:
18-
import pyximport
19-
pyximport.install()
20-
2117
try:
2218
import unittest2 as unittest
2319
except ImportError:
@@ -28,12 +24,12 @@ def cyimport(import_path):
2824
Import a Cython module if available, otherwise return None
2925
(and skip any relevant tests).
3026
"""
31-
try:
32-
return __import__(import_path, fromlist=[True])
33-
except ImportError:
34-
if HAVE_CYTHON:
35-
raise
36-
return None
27+
if HAVE_CYTHON:
28+
import pyximport
29+
py_importer, pyx_importer = pyximport.install()
30+
mod = __import__(import_path, fromlist=[True])
31+
pyximport.uninstall(py_importer, pyx_importer)
32+
return mod
3733

3834

3935
# @cythontest

0 commit comments

Comments
 (0)