How to make the output less verbose in Pytest?
Asked Answered
B

3

6

I am running pytest with tavern for a small testing API project. Failing a test, throws me a bunch of verbose errors plus the response I am expecting to get (why it failed). How can I make pytest less verbose?

I tried pytest --tb=short, pytest -vv, pytest --tavern-beta-new-traceback and none worked as expected just telling me the reason it failed. Something like:

E   tavern.util.exceptions.TestFailError: Test 'Do something' failed:
    - Status code was 200, expected 300
-------------------------------------------------------- Captured log call --------------------------------------------------------
base.py                     41 ERROR    Status code was 200, expected 300
==================================================== 1 failed in 0.38 seconds =====================================================

Maybe is something wrong with how tavern handles errors or pytest?

Brawny answered 10/5, 2019 at 7:4 Comment(1)
Having the same problem. I saw that your issue was closed, saying that it's a pytest config problem but none of the command line options provided in the documention links work as intended.Concordant
E
7

Running pytest -vv should make your output more verbose. If you want your output to be less verbose, try pytest -q or pytest --quiet.

Eparchy answered 15/10, 2019 at 20:47 Comment(0)
P
3

Sometimes using a higher log level might reduce the pytest output clutter. For example, using

pytest <my_test_folder> --log-cli-level=warning

Different options for log level (from most verbose to least verbose) are: debug, info, warning, error and critical.

Pyrotechnics answered 18/9, 2020 at 7:54 Comment(1)
Where in the documentation might I have found those log levels documented?Gallaway
R
0

You can change the verbosity of the output with --verbosity=VERBOSE below:

pytest --help
...
--verbosity=VERBOSE   Set verbosity. Default: 0.

So, --verbosity=1 below can get the output verbosely. *It is identical to -v and --verbose:

pytest --verbosity=1

And, --verbosity=0 below can get the output normally:

pytest --verbosity=0

--verbosity=-1 below can get the output less verbosely. *It is identical to -q and --quiet:

pytest --verbosity=-1
Ruck answered 5/8, 2023 at 0:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.