python - 如何在 py.test 中显示警告

标签 python django testing pytest pytest-django

我刚刚跑了py.test在我的代码上并得到以下输出:

================== 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 中断言警告,而不是显示在命令行上生成的警告。

最佳答案

在这种情况下,pytest-warnings 是为 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
...

关于python - 如何在 py.test 中显示警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33363433/

相关文章:

python - 我需要帮助用立方体形成一个圆圈,使用 blender 2.69 和 python 引擎

c# - 如何在 Windows 上使用 Python for .NET 进行多处理?

angular - 如何在 Angular 单元测试中测试文档点击

url - 如何设置******.domain.com

python - 无法安装 fancyimpute 以在 Jupyter 中使用

python - 在 Lambda Python MediaConvert 函数上设置 ACL

django - 如何通过字符串查询

python - 在 django 1.5 中以一种形式使用两个模型

python - 如何在 stackoverflow 上测试 Django 问题的答案

Android 测试 = 打开已经关闭的数据库