summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@googlemail.com>2012-03-06 14:36:03 -0800
committerRalf Gommers <ralf.gommers@googlemail.com>2012-03-06 14:36:03 -0800
commit8670ca3b83991faf90d57363b551fdc90a196826 (patch)
tree5acac351b3936774282a743fa8c8f58b9638d8d9
parent7c070892e22d988e663e9b2ec3ba9d60c47696e8 (diff)
parent723303deb2e130ad2226edb3ada7eaa351897542 (diff)
downloadnumpy-8670ca3b83991faf90d57363b551fdc90a196826.tar.gz
Merge pull request #219 from mwiebe/test_warn_param
Add parameters in NoseTester constructor as well as in NoseTester.test() to control which warnings raise an error. An explicit difference is made between the master branch and release branches. This was mentioned on the ML: http://thread.gmane.org/gmane.comp.python.numeric.general/48210
-rw-r--r--doc/HOWTO_RELEASE.rst.txt10
-rw-r--r--doc/TESTS.rst.txt7
-rw-r--r--numpy/testing/nosetester.py69
3 files changed, 59 insertions, 27 deletions
diff --git a/doc/HOWTO_RELEASE.rst.txt b/doc/HOWTO_RELEASE.rst.txt
index c31201801..50b82ac8b 100644
--- a/doc/HOWTO_RELEASE.rst.txt
+++ b/doc/HOWTO_RELEASE.rst.txt
@@ -187,6 +187,16 @@ Check the buildbot
------------------
The buildbot is located at `<http://buildbot.scipy.org/>`_.
+Handle test warnings
+--------------------
+The default behavior of the test suite in the master branch is to report errors
+for DeprecationWarnings and RuntimeWarnings that are issued. For a released
+version this is not desired. Therefore any known warnings should be solved or
+explicitly silenced before making the release branch, then when the branch is
+made, the default behavior should be switched to not raise errors. This is
+done in the constructor of the NoseTester class in numpy/testing/nosetester.py,
+by replacing ``raise_warnings="develop"`` with ``raise_warnings="release"``.
+
Make sure current trunk builds a package correctly
--------------------------------------------------
::
diff --git a/doc/TESTS.rst.txt b/doc/TESTS.rst.txt
index a192a32b7..a6387d7b2 100644
--- a/doc/TESTS.rst.txt
+++ b/doc/TESTS.rst.txt
@@ -41,13 +41,6 @@ follows::
>>> import numpy
>>> numpy.test()
-Note that for Python >= 2.7 deprecation warnings are silent by default. They
-can be turned on (recommended after installation and before upgrading) by
-starting the interpreter with the -Wd switch, or by::
-
- >>> import warnings
- >>> warnings.simplefilter('always', DeprecationWarning)
-
The test method may take two or more arguments; the first is a string
label specifying what should be tested and the second is an integer
giving the level of output verbosity. See the docstring for numpy.test
diff --git a/numpy/testing/nosetester.py b/numpy/testing/nosetester.py
index 074ac1766..847d7439a 100644
--- a/numpy/testing/nosetester.py
+++ b/numpy/testing/nosetester.py
@@ -104,10 +104,26 @@ class NoseTester(object):
Parameters
----------
- package : module, str or None
+ package : module, str or None, optional
The package to test. If a string, this should be the full path to
the package. If None (default), `package` is set to the module from
which `NoseTester` is initialized.
+ raise_warnings : str or sequence of warnings, optional
+ This specifies which warnings to configure as 'raise' instead
+ of 'warn' during the test execution. Valid strings are:
+
+ - "develop" : equals ``(DeprecationWarning, RuntimeWarning)``
+ - "release" : equals ``()``, don't raise on any warnings.
+
+ See Notes for more details.
+
+ Notes
+ -----
+ The default for `raise_warnings` is ``(DeprecationWarning, RuntimeWarning)``
+ for the master branch of NumPy, and ``()`` for maintenance branches and
+ released versions. The purpose of this switching behavior is to catch as
+ many warnings as possible during development, but not give problems for
+ packaging of released versions.
"""
# Stuff to exclude from tests. These are from numpy.distutils
@@ -117,16 +133,7 @@ class NoseTester(object):
'pyrex_ext',
'swig_ext']
- def __init__(self, package=None):
- ''' Test class init
-
- Parameters
- ----------
- package : string or module
- If string, gives full path to package
- If None, extract calling module path
- Default is None
- '''
+ def __init__(self, package=None, raise_warnings="develop"):
package_name = None
if package is None:
f = sys._getframe(1)
@@ -143,12 +150,15 @@ class NoseTester(object):
self.package_path = package_path
- # find the package name under test; this name is used to limit coverage
- # reporting (if enabled)
+ # Find the package name under test; this name is used to limit coverage
+ # reporting (if enabled).
if package_name is None:
package_name = get_package_name(package_path)
self.package_name = package_name
+ # Set to "release" in constructor in maintenance branches.
+ self.raise_warnings = raise_warnings
+
def _test_argv(self, label, verbose, extra_argv):
''' Generate argv for nosetest command
@@ -252,8 +262,9 @@ class NoseTester(object):
argv += ['--with-' + plug.name]
return argv, plugins
- def test(self, label='fast', verbose=1, extra_argv=None, doctests=False,
- coverage=False):
+ def test(self, label='fast', verbose=1, extra_argv=None,
+ doctests=False, coverage=False,
+ raise_warnings=None):
"""
Run tests for module using nose.
@@ -279,6 +290,12 @@ class NoseTester(object):
If True, report coverage of NumPy code. Default is False.
(This requires the `coverage module:
<http://nedbatchelder.com/code/modules/coverage.html>`_).
+ raise_warnings : str or sequence of warnings, optional
+ This specifies which warnings to configure as 'raise' instead
+ of 'warn' during the test execution. Valid strings are:
+
+ - "develop" : equals ``(DeprecationWarning, RuntimeWarning)``
+ - "release" : equals ``()``, don't raise on any warnings.
Returns
-------
@@ -325,15 +342,27 @@ class NoseTester(object):
import doctest
doctest.master = None
+ if raise_warnings is None:
+ raise_warnings = self.raise_warnings
+
+ _warn_opts = dict(develop=(DeprecationWarning, RuntimeWarning),
+ release=())
+ 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__()
try:
-
- # Force deprecation warnings to raise
- warnings.filterwarnings('error', category=DeprecationWarning)
- # Force runtime warnings to raise
- warnings.filterwarnings('error', category=RuntimeWarning)
+ # 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)
argv, plugins = self.prepare_test_args(label, verbose, extra_argv,
doctests, coverage)