本文介绍了pytest 报告太多断言失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
pytest 有没有办法只输出一行断言错误?
Is there a way for pytest to only output a single line assert errors?
当你有带有断言的模块时会出现这个问题,如果这些断言失败,它会转储整个断言失败的函数.
This problem arises when you have modules with asserts, If those asserts fails, it dumps the entire function that failed the asserts.
> 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 输出中.
In this case the idtest.testapi.midbusiness() is shown entirely in the pytest output.
推荐答案
调整traceback打印模式(--tb
):
Adjust the traceback print mode (--tb
):
$ pytest --help
--tb=style traceback print mode (auto/long/short/line/native/no).
例如pytest --tb=no
根本不会打印任何痕迹.
E.g. pytest --tb=no
will not print any trace at all.
这篇关于pytest 报告太多断言失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!