pytest reports too much on assert failures
Asked Answered
C

1

7

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.

Cf answered 11/6, 2019 at 10:59 Comment(2)
pytest --tb={auto,long,short,line,native,no}. E.g. pytest --tb=no will not print any trace at all.Hayfield
@hoefling, --tb=short gives me exaclty what I wantCf
H
10

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.

Hayfield answered 11/6, 2019 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.