pytest: only print summary on stdout, but capture test output to file

Viewed 140

What I want to achieve is the following:

When running pytest, i want only to see a line per test, with nothing on stdout. If a test fails, then output of the failing test should be printed. This is the default behavior of pytest and it suits me well.

However, I also want the stdout and stderr of all tests to be written to a log file. Preferably, written so that the output from different tests can be distinguished. I couldn't find an option for doing so.

In Pytest capture stdout of a certain test a hook is added which does something similar (but for a subset of tests). I could adapt this, but I was wondering if there was not something already in pytest? Or a plugin?

0 Answers
Related