Skip to content

Commit 93f3eb7

Browse files
committed
Improved stdout capture
1 parent 83a22ea commit 93f3eb7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pytest_insubprocess.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
import subprocess
34
import sys
45
import tempfile
@@ -10,6 +11,8 @@
1011
import xmltodict
1112
from _pytest.reports import TestReport
1213

14+
SYSTEM_OUT_REGEX = re.compile(r'-+ Captured Out -*\n(?P<stdout>.*)', re.MULTILINE | re.DOTALL)
15+
1316

1417
def pytest_configure(config: pytest.Config) -> None:
1518
config.addinivalue_line('markers', 'insubprocess: run test in an isolated subprocess')
@@ -103,7 +106,11 @@ def _parse_xml_report(item: pytest.Item, junit_xml: str) -> TestReport:
103106

104107
capture = item.config.getoption('--capture')
105108
if capture in ['no', 'tee-sys']:
106-
print(system_out)
109+
match = SYSTEM_OUT_REGEX.search(system_out)
110+
if match:
111+
print(match['stdout'])
112+
else:
113+
print(system_out)
107114

108115
# Create the test report
109116
report = TestReport(

0 commit comments

Comments
 (0)