diff options
author | Stephan Hoyer <shoyer@climate.com> | 2016-01-14 22:06:15 -0800 |
---|---|---|
committer | Stephan Hoyer <shoyer@climate.com> | 2016-01-14 22:12:56 -0800 |
commit | d588b48a0e2fd4a78cadc1336571f59ba6be83c6 (patch) | |
tree | 3e1b59a65862916c40385ddb998b6df6e476ae38 /numpy/testing/tests | |
parent | aa6335c494e4807d65404d91e0e9d25a7d2fe338 (diff) | |
download | numpy-d588b48a0e2fd4a78cadc1336571f59ba6be83c6.tar.gz |
TST: Make assert_warns an optional contextmanager
Diffstat (limited to 'numpy/testing/tests')
-rw-r--r-- | numpy/testing/tests/test_utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 92a00f712..46c7fde5b 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -465,6 +465,21 @@ class TestWarns(unittest.TestCase): assert_equal(before_filters, after_filters, "assert_warns does not preserver warnings state") + def test_context_manager(self): + + before_filters = sys.modules['warnings'].filters[:] + with assert_warns(UserWarning): + warnings.warn("yo") + after_filters = sys.modules['warnings'].filters + + def no_warnings(): + with assert_no_warnings(): + warnings.warn("yo") + + assert_raises(AssertionError, no_warnings) + assert_equal(before_filters, after_filters, + "assert_warns does not preserver warnings state") + def test_warn_wrong_warning(self): def f(): warnings.warn("yo", DeprecationWarning) |