In case of test failure, pytest currently reports the full back trace, excluding pytest's own functions.
This way to report the back traces works well when testing the code from a python module, but is not optimal when using an external library in the test.
It is possible to exclude entries from the back traces with __tracebackhide__ = True, but it is an invasive solution for the library that
the authors may not want to implement,
may not be implemented yet when the tester is using the library.
Describe the solution you'd like
I would much prefer a way to hide the functions that are not part of the currently tested project. We could use the module installation path to find out whether the module is installed or in the project sources. Testing if site-packages is in the module path is probably a bit rough but has worked for us so far!
A --hide-external-trace=yes command line option could be used to activate this feature.
when doing some webui testing, the internal methods from the library used to interact with the webbrowser are of very little interest for the test writter. The tester most likely want to exclude them from the trace backs.
when using a test helper library, like pytest-bdd, the library internal methods appear in the back traces before the back traces from the code written by the tester. The helper library could hide them (in fact I've opened a PR in pytest-bdd: https://github.com/pytest-dev/pytest-bdd/pull/557), in the mean time this option could help to cleanup the failure reports.
Alternative Solutions
I've proposed a quite ugly monkey patch in the SO posts listed below.
What's the problem this feature will solve?
In case of test failure, pytest currently reports the full back trace, excluding pytest's own functions. This way to report the back traces works well when testing the code from a python module, but is not optimal when using an external library in the test.
It is possible to exclude entries from the back traces with
__tracebackhide__ = True
, but it is an invasive solution for the library thatDescribe the solution you'd like
I would much prefer a way to hide the functions that are not part of the currently tested project. We could use the module installation path to find out whether the module is installed or in the project sources. Testing if
site-packages
is in the module path is probably a bit rough but has worked for us so far!A
--hide-external-trace=yes
command line option could be used to activate this feature.when doing some webui testing, the internal methods from the library used to interact with the webbrowser are of very little interest for the test writter. The tester most likely want to exclude them from the trace backs.
when using a test helper library, like pytest-bdd, the library internal methods appear in the back traces before the back traces from the code written by the tester. The helper library could hide them (in fact I've opened a PR in pytest-bdd: https://github.com/pytest-dev/pytest-bdd/pull/557), in the mean time this option could help to cleanup the failure reports.
Alternative Solutions
I've proposed a quite ugly monkey patch in the SO posts listed below.
Additional context
A couple of SO questions related to that problem:
https://stackoverflow.com/questions/24402456/py-test-hide-stacktrace-lines-from-unittest-module
https://stackoverflow.com/questions/22912747/py-test-tracebacks-highlight-my-code-fold-frames-of-framework
I would be interested in creating a PR for this feature — just checking if pytest authors might be interested before going further :smile: