如何在py.tes中显示警告

2024-04-27 17:37:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚对代码运行了^{},得到了以下输出:

================== 6 passed, 2 pytest-warnings in 40.79 seconds =======================

但是,我看不出py.test想警告我什么。如何打开控制台的警告输出?

py.test --help为我提供了--strict标志:

--strict run pytest in strict mode, warnings become errors.

但是我只想看到输出,而不是让我的测试失败。

我检查了pytest.orgthis question,但它们只关心在python中断言警告,而不显示在命令行上生成的警告。


Tags: runinpytest警告pytestmode标志
1条回答
网友
1楼 · 发布于 2024-04-27 17:37:24

在本例中,pytest警告是为pytest和/或其插件生成的警告。这些警告不是为您的代码生成的。为了在报告中列出它们,您需要使用选项-r w。这里是py.test --help的一部分:

-r chars              show extra test summary info as specified by chars (f)ailed,
                      (E)error, (s)skipped, (x)failed, (X)passed
                      (w)pytest-warnings (a)all.

这将允许在报告中显示警告(记录的顶部)将列出哪些pytest插件使用不推荐的参数(在我的示例中如下所示):

...
================================ pytest-warning summary ================================ 
WI1 /Projects/.tox/py27/lib/python2.7/site-packages/pytest_timeout.py:68 'pytest_runtest_protocol' hook uses deprecated __multicall__ argument
WI1 /Projects/.tox/py27/lib/python2.7/site-packages/pytest_capturelog.py:171 'pytest_runtest_makereport' hook uses deprecated __multicall__ argument
...

相关问题 更多 >