I'm running into some trouble with filtering warnings in python tests when using nosetests
. I'd like my call to warn.filterwarnings
to be local only to a single file, but instead if any of the files I test with nosetests
calls warn.filterwarnings
, warnings are filtered in all of the tests. For example (from the scikit-bio code base), skbio/math/diversity/beta/tests/test_base.py
does not have a call to warn.filterwarnings
, so as expected if a warning is generated during the tests, it is printed to the screen:
$ nosetests skbio/math/diversity/beta/tests/test_base.py
../Users/caporaso/Dropbox/code/skbio/skbio/math/diversity/beta/base.py:89: UserWarning: pw_distances_from_table is deprecated. In the future (tentatively scikit-bio 0.2.0), pw_distance will take a biom.table.Table object and this function will be removed. You will need to update your code to call pw_distances at that time.
warn("pw_distances_from_table is deprecated. In the future (tentatively "
...
----------------------------------------------------------------------
Ran 5 tests in 0.017s
OK
However, in skbio/core/alignment/tests/test_pairwise.py
, there is a call to warn.filterwarnings
. If I run those tests before skbio/math/diversity/beta/tests/test_base.py
, the above warning is not printed:
$ nosetests skbio/core/alignment/tests/test_pairwise.py skbio/math/diversity/beta/tests/test_base.py
...................
----------------------------------------------------------------------
Ran 19 tests in 0.056s
OK
I'd like to have the warning from skbio/math/diversity/beta/tests/test_base.py
printed, even if other warn.filterwarnings
is called from other test files. In practice, I'll end up filtering that as well, but I want to know if there are other warnings not being caught by the tests elsewhere in my test suite.
Ideally you want to use conext managers to temporarily suppress them.