How to run pytest via pycharm and have all output in the run window, during the test run?

I am trying to run a pytest test that takes a long time to run, and has some prints to stdout/stderr which I want to be able to see.

All I could find regarding this was this SO answer

According to that answer, I can specify `-s` under run configurations > additional arguments.

Another answer claims `--capture=tee-sys` will solve that issue.


Both fail, and I have to wait for the test to finish in order to see output. This greatly hinders development, as I can't quickly see results, and am forced to create a regular script which is not a pytest in order to debug my code, then copy it as a test.


For reproducibility, I am referring to Pytorch-lightning's tests.


How can I see pytest output *during the test run*?

1 comment
Comment actions Permalink

I believe you can do this using pytest's inbuilt capsys fixture without any special command line options. If you try running the following as a test in PyCharm. Unfortunately the final output still rather garbled with the debug statements from the test that passes being shown erroneously, but while running it's quite nice I think.

import time

def test_func1(capsys):
for _ in range(10):
print("debug output from test 1")
with capsys.disabled():
print("progress update 1")
with capsys.disabled():
print("progress update 2")
assert True

def test_func2(capsys):
for _ in range(10):
print("debug output from test 2")
with capsys.disabled():
print("progress update 3")
with capsys.disabled():
print("progress update 4")
assert False

Please sign in to leave a comment.