summaryrefslogtreecommitdiff
path: root/numpy/lib/tests
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2014-02-21 21:13:29 +0100
committerSebastian Berg <sebastian@sipsolutions.net>2014-02-21 21:13:29 +0100
commitfd399aaee5b703744f508fb2ce4718e1f4bc8984 (patch)
tree956f5b80e179b8639b3cf962a909ac88ede60c70 /numpy/lib/tests
parent8997167e0de90b7132787ff869ba7988783bb133 (diff)
downloadnumpy-fd399aaee5b703744f508fb2ce4718e1f4bc8984.tar.gz
TST: do not use "ignore" to filter warnings
When a warning is ignored (or raised once) in python, the warnings module will tag on a `__warningregistry__` dictionary to be able to filter these warnings in the future. This is tagged on to the current context, causing leakage to later calls (this is a bit more complex, since where the registry ends up depends on the layers between the original caller and warner). In short, tests should typically not use ignore but catch the warnings to avoid changing the user experience (or errors on duplicate test runs). Fixes an error on duplicate test runs (does not remove all "ignores" which may change behaviour outside tests). Closes gh-4340
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r--numpy/lib/tests/test_function_base.py16
-rw-r--r--numpy/lib/tests/test_nanfunctions.py4
2 files changed, 10 insertions, 10 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 003d3e541..fee838ecf 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -1222,8 +1222,8 @@ class TestCorrCoef(TestCase):
assert_allclose(np.corrcoef(x, y), np.array([[1., -1.j], [1.j, 1.]]))
def test_empty(self):
- with warnings.catch_warnings():
- warnings.simplefilter('ignore', RuntimeWarning)
+ with warnings.catch_warnings(record=True):
+ warnings.simplefilter('always', RuntimeWarning)
assert_array_equal(corrcoef(np.array([])), np.nan)
assert_array_equal(corrcoef(np.array([]).reshape(0, 2)),
np.array([]).reshape(0, 0))
@@ -1232,8 +1232,8 @@ class TestCorrCoef(TestCase):
def test_wrong_ddof(self):
x = np.array([[0, 2], [1, 1], [2, 0]]).T
- with warnings.catch_warnings():
- warnings.simplefilter('ignore', RuntimeWarning)
+ with warnings.catch_warnings(record=True):
+ warnings.simplefilter('always', RuntimeWarning)
assert_array_equal(corrcoef(x, ddof=5),
np.array([[np.nan, np.nan], [np.nan, np.nan]]))
@@ -1253,8 +1253,8 @@ class TestCov(TestCase):
assert_allclose(cov(x, y), np.array([[1., -1.j], [1.j, 1.]]))
def test_empty(self):
- with warnings.catch_warnings():
- warnings.simplefilter('ignore', RuntimeWarning)
+ with warnings.catch_warnings(record=True):
+ warnings.simplefilter('always', RuntimeWarning)
assert_array_equal(cov(np.array([])), np.nan)
assert_array_equal(cov(np.array([]).reshape(0, 2)),
np.array([]).reshape(0, 0))
@@ -1263,8 +1263,8 @@ class TestCov(TestCase):
def test_wrong_ddof(self):
x = np.array([[0, 2], [1, 1], [2, 0]]).T
- with warnings.catch_warnings():
- warnings.simplefilter('ignore', RuntimeWarning)
+ with warnings.catch_warnings(record=True):
+ warnings.simplefilter('always', RuntimeWarning)
assert_array_equal(cov(x, ddof=5),
np.array([[np.inf, -np.inf], [-np.inf, np.inf]]))
diff --git a/numpy/lib/tests/test_nanfunctions.py b/numpy/lib/tests/test_nanfunctions.py
index af01a7167..df332dfb1 100644
--- a/numpy/lib/tests/test_nanfunctions.py
+++ b/numpy/lib/tests/test_nanfunctions.py
@@ -130,8 +130,8 @@ class TestNanFunctions_ArgminArgmax(TestCase):
def test_result_values(self):
for f, fcmp in zip(self.nanfuncs, [np.greater, np.less]):
for row in _ndat:
- with warnings.catch_warnings():
- warnings.simplefilter('ignore')
+ with warnings.catch_warnings(record=True):
+ warnings.simplefilter('always')
ind = f(row)
val = row[ind]
# comparing with NaN is tricky as the result