summaryrefslogtreecommitdiff
path: root/numpy/tests/test_reloading.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2020-05-14 14:27:29 -0500
committerSebastian Berg <sebastian@sipsolutions.net>2020-12-15 12:39:47 -0600
commit7628292e005fd3d6faf1b77434d2224921d49ad8 (patch)
tree8566c77c58f7780e663bc0a5c706b5f21d37536b /numpy/tests/test_reloading.py
parent74e135b261e4613963cc50ddb97ac2edbd5936ba (diff)
downloadnumpy-7628292e005fd3d6faf1b77434d2224921d49ad8.tar.gz
DOC: Warn when reloading numpy or using numpy in sub-interpreter
This adds a warning when the main NumPy module is reloaded with the assumption that in this case objects such as `np.matrix`, `np._NoValue` or exceptions may be cached internally. It also gives a warning when NumPy is imported in a sub-interpreter.
Diffstat (limited to 'numpy/tests/test_reloading.py')
-rw-r--r--numpy/tests/test_reloading.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/numpy/tests/test_reloading.py b/numpy/tests/test_reloading.py
index 61ae91b00..5c4309f4a 100644
--- a/numpy/tests/test_reloading.py
+++ b/numpy/tests/test_reloading.py
@@ -1,4 +1,4 @@
-from numpy.testing import assert_raises, assert_, assert_equal
+from numpy.testing import assert_raises, assert_warns, assert_, assert_equal
from numpy.compat import pickle
import sys
@@ -16,13 +16,15 @@ def test_numpy_reloading():
VisibleDeprecationWarning = np.VisibleDeprecationWarning
ModuleDeprecationWarning = np.ModuleDeprecationWarning
- reload(np)
+ with assert_warns(UserWarning):
+ reload(np)
assert_(_NoValue is np._NoValue)
assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning)
assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
assert_raises(RuntimeError, reload, numpy._globals)
- reload(np)
+ with assert_warns(UserWarning):
+ reload(np)
assert_(_NoValue is np._NoValue)
assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning)
assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
@@ -45,13 +47,15 @@ def test_full_reimport():
# This is generally unsafe, especially, since we also reload the C-modules.
code = textwrap.dedent(r"""
import sys
+ from pytest import warns
import numpy as np
for k in list(sys.modules.keys()):
if "numpy" in k:
del sys.modules[k]
- import numpy as np
+ with warns(UserWarning):
+ import numpy as np
""")
p = subprocess.run([sys.executable, '-c', code])
- assert p.returncode == 0
+