I'm using pytest with pytest-xdist for parallel test running. It doesn't seem to honour the -s option for passing through the standard output to the terminal as the tests are run. Is there any way to make this happen? I realise this could cause the output from the different processes to be jumbled up in the terminal but I'm ok with that.
Why does pytest + xdist not capture output?
5.2k Views Asked by Andrew Magee At
3
There are 3 best solutions below
5
On
I found a workaround, although not a full solution. By redirecting stdout to stderr, the output of print statements is displayed. This can be accomplished with a single line of Python code:
sys.stdout = sys.stderr
If placed in conftest.py, it applies to all tests.
0
On
Steve's solution is great but sometimes we can't modifiy an conftest.py shared file.
I use -s argument on pytest command :
pytest -s path/test_file.py
Inside my Python code I use these lines :
import sys
print("\nMy DEBUG line", file=sys.stderr)
pytest prompt me my DEBUG line. You can improve this solution according to your needs.
I used the followed code:
Insert it to conftest.py
The main thing is to be sure that it is remote session, and we have to reconfigure CaptureManager instance. There one unresolved issue is how to check that remote object has "
__channelexec__.SlaveInteractor" type.