这是How do I find where a "Sorting because non-concatenation" warning is coming from?的扩展。
在我的pytest中,我仍然收到相同的警告。我在这里看了几个问题,并做了:
import warnings
warnings.filterwarnings('error')
这在How do I catch a numpy warning like it's an exception (not just for testing)?中建议
但是,当我运行pytest时,它仍然给我错误,但实际上没有错误...
答案 0 :(得分:0)
正如Warnings Capture的pytest文档所说,您可以通过以下几种方法来做到这一点:
1)使用-W error::Warning
运行pytest,它将在每次发生警告时使测试崩溃
2)使用此部分修改您的pytest.ini
:
[pytest]
filterwarnings =
error
3)设置适用于模块中所有测试的变量pytestmark
:
pytestmark = pytest.mark.filterwarnings("error")
答案 1 :(得分:0)