diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-07-11 20:29:08 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-07-12 07:27:07 -0600 |
commit | 05a15c8b621f953607429f3b67e079dfe1b439d6 (patch) | |
tree | c3c851bffa1d85399b4547f2a1620ad87c2c07bc /numpy/testing/nosetester.py | |
parent | a053a4372aba0af0bd63ffd5e207baf469cfc7bf (diff) | |
download | numpy-05a15c8b621f953607429f3b67e079dfe1b439d6.tar.gz |
MAINT: Remove uses of the WarningManager class.
WarningManager was a workaround for the lack of the with statement
in Python versions < 2.6. As those versions are no longer supported
it can be removed.
Deprecation notes are added to WarningManager and WarningMessage, but
to avoid a cascade of messages in third party apps, no warnings are
raised at this time, that can be done later.
Closes #3519.
Diffstat (limited to 'numpy/testing/nosetester.py')
-rw-r--r-- | numpy/testing/nosetester.py | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/numpy/testing/nosetester.py b/numpy/testing/nosetester.py index f1ebd2265..f11f04b20 100644 --- a/numpy/testing/nosetester.py +++ b/numpy/testing/nosetester.py @@ -363,32 +363,27 @@ class NoseTester(object): if raise_warnings in _warn_opts.keys(): raise_warnings = _warn_opts[raise_warnings] - # Preserve the state of the warning filters - warn_ctx = numpy.testing.utils.WarningManager() - warn_ctx.__enter__() - # Reset the warning filters to the default state, - # so that running the tests is more repeatable. - warnings.resetwarnings() - # If deprecation warnings are not set to 'error' below, - # at least set them to 'warn'. - warnings.filterwarnings('always', category=DeprecationWarning) - # Force the requested warnings to raise - for warningtype in raise_warnings: - warnings.filterwarnings('error', category=warningtype) - # Filter out annoying import messages. - warnings.filterwarnings('ignore', message='Not importing directory') - warnings.filterwarnings("ignore", message="numpy.dtype size changed") - warnings.filterwarnings("ignore", message="numpy.ufunc size changed") - warnings.filterwarnings("ignore", category=ModuleDeprecationWarning) - - try: + with warnings.catch_warnings(): + # Reset the warning filters to the default state, + # so that running the tests is more repeatable. + warnings.resetwarnings() + # If deprecation warnings are not set to 'error' below, + # at least set them to 'warn'. + warnings.filterwarnings('always', category=DeprecationWarning) + # Force the requested warnings to raise + for warningtype in raise_warnings: + warnings.filterwarnings('error', category=warningtype) + # Filter out annoying import messages. + warnings.filterwarnings('ignore', message='Not importing directory') + warnings.filterwarnings("ignore", message="numpy.dtype size changed") + warnings.filterwarnings("ignore", message="numpy.ufunc size changed") + warnings.filterwarnings("ignore", category=ModuleDeprecationWarning) + from .noseclasses import NumpyTestProgram - argv, plugins = self.prepare_test_args(label, - verbose, extra_argv, doctests, coverage) + argv, plugins = self.prepare_test_args( + label, verbose, extra_argv, doctests, coverage) t = NumpyTestProgram(argv=argv, exit=False, plugins=plugins) - finally: - warn_ctx.__exit__() return t.result |