Permalink
Browse files

TST: Make deprecation warnings raise exceptions during test run

  • Loading branch information...
1 parent 27befc8 commit d93d0214eaec2cd45119ad1f7485e5628faffc2a @mwiebe mwiebe committed Feb 7, 2012
Showing with 19 additions and 9 deletions.
  1. +2 −5 README.txt
  2. +17 −4 numpy/testing/nosetester.py
View
@@ -16,11 +16,8 @@ After installation, tests can be run with:
python -c 'import numpy; numpy.test()'
-When installing a new version of numpy for the first time or before upgrading
-to a newer version, it is recommended to turn on deprecation warnings when
-running the tests:
-
-python -Wd -c 'import numpy; numpy.test()'
+Starting in NumPy 1.7, deprecation warnings have been set to 'raise' by
+default, so the -Wd command-line option is no longer necessary.
The most current development version is always available from our
git repository:
@@ -6,6 +6,8 @@
"""
import os
import sys
+import warnings
+import numpy.testing.utils
def get_package_name(filepath):
"""
@@ -323,10 +325,21 @@ def test(self, label='fast', verbose=1, extra_argv=None, doctests=False,
import doctest
doctest.master = None
- argv, plugins = self.prepare_test_args(label, verbose, extra_argv,
- doctests, coverage)
- from noseclasses import NumpyTestProgram
- t = NumpyTestProgram(argv=argv, exit=False, plugins=plugins)
+ # Preserve the state of the warning filters
+ warn_ctx = numpy.testing.utils.WarningManager()
+ warn_ctx.__enter__()
+ try:
+
+ # Force deprecation warnings to raise
+ warnings.filterwarnings('error', category=DeprecationWarning)
+
+ argv, plugins = self.prepare_test_args(label, verbose, extra_argv,
+ doctests, coverage)
+ from noseclasses import NumpyTestProgram
+ t = NumpyTestProgram(argv=argv, exit=False, plugins=plugins)
+ finally:
+ warn_ctx.__exit__()
+
return t.result
def bench(self, label='fast', verbose=1, extra_argv=None):

4 comments on commit d93d021

Owner

rgommers replied Feb 11, 2012

This causes an error with scipy 0.10, which shows one DeprecationWarning when running the tests. I never figured out how to suppress that one, because the whole module (maxentropy) was deprecated in __init__.py.

Probably the best solution is to make this behavior configurable by a keyword in the NoseTester constructor, and off by default. Same for RuntimeWarning. @mwiebe: do you agree?

I can do this tomorrow.

Member

mwiebe replied Feb 11, 2012

Making it configurable is a good idea, but I'd like it better if it were on by default, instead of off. It's a general best practice thing, and I'd like numpy to eventually increase the C compiler warning level by default among other things as well.

Is it possible to wrap everything in the maxentropy tests with a warning manager, initialized before the import maxentropy line? I'd like to explore how we might solve this a bit more before considering an "off by default" approach.

Owner

rgommers replied Feb 12, 2012

It's just a matter of timing. I agree on by default is ideal, but we can't go back and fix already released versions of scipy and other projects. So how about off for 1.7, advertising this in the release notes, and then for 1.8 turn it on.

Scipy is also not the only project that uses NoseTester.

Owner

rgommers replied Feb 12, 2012

And the warning manager for maxentropy can't work, unless I'm missing something. If you do that, no one will ever see the warning. Unless you want to let the warning manager somehow figure out whether it's called by nose or not.

Please sign in to comment.