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
.
Disable Pytest for you projectOpen the Settings/Preferences | Tools | Python Integrated Tools settings dialog as described in Choosing Your Testing Framework. In the Default test runner field select Unittests. Click OK to save the settings.
If you call pytest. fail inside a test, it's a FAIL status for that test (or XFAIL, if it has xfail mark). But, if you call it from a fixture, the test, which depends on this fixture, is getting ERROR state.
pytest allows you to create custom plugins for this sort of functionality. But it also allows you to register those same plugin hooks in your conftest.py files. The above code in your tests/conftest.py file will do the trick. pytest_configure() registers a new marker ( focus ).
Running pytest We can run a specific test file by giving its name as an argument. A specific function can be run by providing its name after the :: characters. Markers can be used to group tests.
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With