问题
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