Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove library code calls from pytest traceback?

I'm using pytest with mock in my python project.

When I get a test failure that involves a mock object (almost all of them), the traceback dives into the mock library source code and my code that's actually triggering the failure often scrolls out of view.

Is there a way to tell py.test to exclude installed libraries from the traceback or something like that? The noise level is taking away from what is otherwise a sweet testing library.

like image 325
scanny Avatar asked Sep 08 '13 05:09

scanny


People also ask

How do I stop pytest?

pytest has the option -x or --exitfirst which stops the execution of the tests instanly on first error or failed test. pytest also has the option --maxfail=num in which num indicates the number of errors or failures required to stop the execution of the tests.

What is the name of the directory that pytest will look at to detect tests?

In the selected directories, pytest looks for test_*. py or *_test.py files.

Where do I put pytest files?

While the pytest discovery mechanism can find tests anywhere, pytests must be placed into separate directories from the product code packages. These directories may either be under the project root or under the Python package.


1 Answers

There is a hack: a function defining the local variable __tracebackhide__ will not be shown. Example:

def some_support_code(x, y):
    __tracebackhide__ = True
    assert x == y
like image 74
Armin Rigo Avatar answered Oct 23 '22 15:10

Armin Rigo