Joshua
Joshua

Reputation: 6241

How to disable pytest dumping out source code?

When one of the tests fail, pytest will dump out the source code of the function where the exception is raised. However, something when the error is raised from another library, it still dumps the function source code flood the output.

Is it possible to disable pytest from dump source code and have the stack trace only? Stack trace is usually more than enough to track down the problem.

I have searched a bit but all I can find are posts related to --show-capture.

Upvotes: 21

Views: 5019

Answers (2)

Clare Macrae
Clare Macrae

Reputation: 3799

Here is how to put your chosen option in a pytest.ini file:

[pytest]
# --tb not given    Produces reams of output, with full source code included in tracebacks
# --tb=no           Just shows location of failure in the test file: no use for tracking down errors
# --tb=short        Just shows vanilla traceback: very useful, but file names are incomplete and relative
# --tb=native       Slightly more info than short: still works very well. The full paths may be useful for CI
addopts = --tb=native

The available values for --tb are:

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

Useful links:

Upvotes: 13

Samarth
Samarth

Reputation: 687

You can use the --tb option. You can choose either --tb=short or --tb=native as per what suits you. Check the detailed documentation here.

Upvotes: 28

Related Questions