diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2016-06-19 13:12:54 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2016-09-02 10:10:55 +0200 |
commit | 968507bdfb4467d5ec6e3b6999a5717100782c3c (patch) | |
tree | b79fa7fbb18064f56a0605e6436a91342fb8be7c /numpy/testing/tests/test_utils.py | |
parent | 29a45efa15cf3992ab01b1535d51189319a7592d (diff) | |
download | numpy-968507bdfb4467d5ec6e3b6999a5717100782c3c.tar.gz |
ENH: Make warning testing context managers more specific
This means that warnings of different origin then the one tested for
behave normally. If the normal behaviour is to igonre them this might
decrease specificity in rare cases. In most cases the specificity
will be slightly higher.
Diffstat (limited to 'numpy/testing/tests/test_utils.py')
-rw-r--r-- | numpy/testing/tests/test_utils.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index c0f609883..c191aea5b 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -503,23 +503,21 @@ class TestWarns(unittest.TestCase): warnings.warn("yo", DeprecationWarning) failed = False - filters = sys.modules['warnings'].filters[:] - try: + with warnings.catch_warnings(): + warnings.simplefilter("error", DeprecationWarning) try: - # Should raise an AssertionError + # Should raise a DeprecationWarning assert_warns(UserWarning, f) failed = True - except AssertionError: + except DeprecationWarning: pass - finally: - sys.modules['warnings'].filters = filters if failed: raise AssertionError("wrong warning caught by assert_warn") class TestAssertAllclose(unittest.TestCase): - + def test_simple(self): x = 1e-3 y = 1e-9 |