Where can I find the captured stdout for the py.test test that passes?

I use py.test message hooks (pytest_runtest_makereport () and pytest_report_teststatus ()).

When the py.test test failed, I can find the captured stdout data in the report header (in report.sections []).

When the py.test test passes, the report.sections [] list is empty.

Where can I find the captured stdout for a test that passes?

Thanks.

Edit: From the source (_pytest / capture.py), it looks like this is only available if the test fails:

def pytest_runtest_makereport(self, __multicall__, item, call): ... if not rep.passed: addouterr(rep, outerr) 
+4
source share
1 answer

It turns out that the information is available in item.outerr, which is a tuple of two Unicode strings; the first is stdout and the second is stderr.

Note that py.test indicates these lines in the install, call, and break reports, and some may be empty. Therefore, in order to save the output without overwriting it with an empty string, the logic should be:

 stdout = item.outerr[0] if stdout and len(stdout): whatever.stdout = stdout stderr = item.outerr[1] if stderr and len(stderr): whatever.stderr = stderr 
+2
source

Source: https://habr.com/ru/post/1442356/


All Articles