【发布时间】:2019-06-11 10:59:36
【问题描述】:
有没有办法让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 输出中。
【问题讨论】:
-
pytest --tb={auto,long,short,line,native,no}。例如。pytest --tb=no根本不会打印任何痕迹。 -
@hoefling, --tb=short 给了我想要的东西