pytest reports too much on assert failures

别等时光非礼了梦想. 提交于 2021-01-04 07:47:05

问题


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"}

In this case the idtest.testapi.midbusiness() is shown entirely in the pytest output.


回答1:


Adjust the traceback print mode (--tb):

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

E.g. pytest --tb=no will not print any trace at all.



来源:https://stackoverflow.com/questions/56542216/pytest-reports-too-much-on-assert-failures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!