在使用nosetests
. 我希望我的调用warn.filterwarnings
只对单个文件是本地的,但是如果我使用nosetests
调用测试的任何文件warn.filterwarnings
,警告都会在所有测试中过滤。例如(来自scikit-bio 代码库),skbio/math/diversity/beta/tests/test_base.py
没有对 的调用warn.filterwarnings
,因此如果在测试期间生成警告,则会按预期将其打印到屏幕上:
$ 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
但是,在 中skbio/core/alignment/tests/test_pairwise.py
,有对 的调用warn.filterwarnings
。如果我之前运行这些测试skbio/math/diversity/beta/tests/test_base.py
,则不会打印上述警告:
$ nosetests skbio/core/alignment/tests/test_pairwise.py skbio/math/diversity/beta/tests/test_base.py
...................
----------------------------------------------------------------------
Ran 19 tests in 0.056s
OK
我想skbio/math/diversity/beta/tests/test_base.py
打印警告,即使warn.filterwarnings
从其他测试文件中调用了其他。在实践中,我最终也会对其进行过滤,但我想知道是否还有其他警告没有被我的测试套件中其他地方的测试捕获。