Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does pytest + xdist not capture output?

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.

like image 429
Andrew Magee Avatar asked Nov 19 '14 00:11

Andrew Magee


People also ask

What is pytest Xdist?

The pytest-xdist plugin extends pytest with new test execution modes, the most used being distributing tests across multiple CPUs to speed up test execution: pytest -n auto.

Where does pytest print to?

By default, pytest captures the output to sys. stdout/stderr and redirects it to a temporary file.

Does pytest run in parallel?

Learn Pytest From Scratch By default, pytest runs tests in sequential order. In a real scenario, a test suite will have a number of test files and each file will have a bunch of tests. This will lead to a large execution time. To overcome this, pytest provides us with an option to run tests in parallel.


1 Answers

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.

like image 76
Steve Saporta Avatar answered Sep 20 '22 12:09

Steve Saporta