python - pytest 报告太多断言失败

标签 python pytest verbosity

有没有办法让 pytest 只输出单行断言错误?

当您的模块带有断言时,就会出现此问题,如果这些断言失败,它将转储导致断言失败的整个函数。

> assert r.status_code == 200, f"{idtest.tools.now()} wrong status code {r.status_code}: resp:{r.text}"
E AssertionError: 2019-06-11 12:41:17.239128 wrong status code 500: resp:{"timestamp":"2019-06-11T10:41:17.187+0000","status":500,"error":"Internal Server Error","message":"The user was not found","path":"/mid/business"}

在这种情况下,idtest.testapi.midbusiness() 完全显示在 pytest 输出中。

最佳答案

调整回溯打印模式(--tb):

$ pytest --help
  --tb=style            traceback print mode (auto/long/short/line/native/no).

例如pytest --tb=no 根本不会打印任何跟踪。

关于python - pytest 报告太多断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56542216/

相关文章:

python - Pytest:使用 allure 进行日志记录的最佳实践

r - 沉默vroom::vroom?

python - 如何使用 Python 的 doctest-package 测试字典相等性?

python - 使用 txredisapi 建立连接后订阅和取消订阅 channel

python - 使用私钥进行 Testinfra ssh 执行

maven-2 - Maven : How can I stop the deploy plugin from logging upload progress?

git - Git 是否有调试或详细选项来解释它在做什么?

python - 如何展平元组列表并删除重复项?

python - 如何使用Docker将当前的部署方法迁移到一种方法?

python - 由于运行器当前目录,py.test 测试在 Pycharm 2017.1 中失败