summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/f2py/__init__.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/numpy/f2py/__init__.py b/numpy/f2py/__init__.py
index 949bac0ff..328045c07 100644
--- a/numpy/f2py/__init__.py
+++ b/numpy/f2py/__init__.py
@@ -9,7 +9,6 @@ import subprocess
import os
from . import f2py2e
-from . import f2py_testing
from . import diagnose
run_main = f2py2e.run_main
@@ -113,6 +112,33 @@ def compile(source,
os.remove(fname)
return status
-from numpy._pytesttester import PytestTester
-test = PytestTester(__name__)
-del PytestTester
+
+if sys.version_info[:2] >= (3, 7):
+ # module level getattr is only supported in 3.7 onwards
+ # https://www.python.org/dev/peps/pep-0562/
+ def __getattr__(attr):
+
+ # Avoid importing things that aren't needed for building
+ # which might import the main numpy module
+ if attr == "f2py_testing":
+ import numpy.f2py.f2py_testing as f2py_testing
+ return f2py_testing
+
+ elif attr == "test":
+ from numpy._pytesttester import PytestTester
+ test = PytestTester(__name__)
+ return test
+
+ else:
+ raise AttributeError("module {!r} has no attribute "
+ "{!r}".format(__name__, attr))
+
+ def __dir__():
+ return list(globals().keys() | {"f2py_testing", "test"})
+
+else:
+ from . import f2py_testing
+
+ from numpy._pytesttester import PytestTester
+ test = PytestTester(__name__)
+ del PytestTester