According to the docs https://docs.pytest.org/en/6.2.x/capture.html#using-print-statements-for-debugging using print statements for debugging is a key benefit of using pytest.
However when running from within PyCharm print statements appear mixed in with the test results and appear for tests that pass. This is different to the pytest default behaviour. I've not been able to use Additional Arguments to get the default behaviour.
print("debug output from test 1")
print("debug output from test 2")
Run from PyCharm produces:
simple_test.py::test_func1 PASSED [ 50%]debug output from test 1
simple_test.py::test_func2 FAILED [100%]debug output from test 2
pytest run from Terminal produces:
debug output from test 2
Is there a way to get PyCharm to output the print statements for failed tests only?
I think once I have a large number of tests containing lots of print call then having the passing tests always printing and doing so interleaved with the test results is going to be a deal-breaker for using pytest as an integrated tool, which is a shame since I like the PyCharm UI a lot.
I'm using Ubuntu 20.04.2, PyCharm 2021.1.2 (Community), Python 3.9.2, pytest-6.2.4, conda 4.10.1