diff options
-rw-r--r-- | numpy/core/tests/test_deprecations.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index 3ad264583..e993494ea 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -90,18 +90,17 @@ class _DeprecationTestCase(object): raise AssertionError("%i warnings found but %i expected" % (len(self.log), num)) - warnings.filterwarnings("error", message=self.message, - category=DeprecationWarning) - - try: - function(*args, **kwargs) - if exceptions != tuple(): - raise AssertionError("No error raised during function call") - except exceptions: - if exceptions == tuple(): - raise AssertionError("Error raised during function call") - finally: - warnings.filters.pop(0) + with warnings.catch_warnings(): + warnings.filterwarnings("error", message=self.message, + category=DeprecationWarning) + + try: + function(*args, **kwargs) + if exceptions != tuple(): + raise AssertionError("No error raised during function call") + except exceptions: + if exceptions == tuple(): + raise AssertionError("Error raised during function call") def assert_not_deprecated(self, function, args=(), kwargs={}): |