'print the failed test output right after and not only at the end pytest

I have multiple tests that run as part of a GitLab pipline, the issue is that the tests run became very long and when a test in the middle fails one need to wait to the end of the run to see the output of the failed test.

I'm using the following:

pytest -v -m -rxs --stepwise

Is there a way to print the failed test traceback right after it fails without doing the same for the passed tests



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source