Skip to content

Commit faee13e

Browse files
committed
Re-print test warnings after tests have ran (issue #458).
This works by capturing stderr from tests and checking to see if each line contains the string "WARNING:test:". If a line contains this string it is saved for later and re-printed once all tests have been run.
1 parent 88d5262 commit faee13e

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

test/testall.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,34 @@ def _gen_pythons():
4040
yield ver, python
4141

4242
def testall():
43+
all_warnings = []
4344
for ver, python in _gen_pythons():
4445
if ver < (3, 5):
4546
# Don't support Python < 3.5
4647
continue
4748
ver_str = "%s.%s" % ver
4849
print("-- test with Python %s (%s)" % (ver_str, python))
4950
assert ' ' not in python
51+
5052
proc = subprocess.Popen(
51-
"MACOSX_DEPLOYMENT_TARGET= %s test.py -- -knownfailure" % python,
52-
shell=True
53+
# pass "-u" option to force unbuffered output
54+
"MACOSX_DEPLOYMENT_TARGET= %s -u test.py -- -knownfailure" % python,
55+
shell=True, stderr=subprocess.PIPE
5356
)
54-
rv = proc.wait()
55-
if rv:
56-
sys.exit(os.WEXITSTATUS(rv))
57+
58+
while proc.poll() is None:
59+
# capture and re-print stderr while process is running
60+
line = proc.stderr.readline().decode().strip()
61+
print(line, file=sys.stderr)
62+
if 'WARNING:test:' in line:
63+
# if stderr contains a warning, save this for later
64+
all_warnings.append((python, ver_str, line))
65+
66+
if proc.returncode:
67+
sys.exit(os.WEXITSTATUS(proc.returncode))
68+
69+
for python, ver_str, warning in all_warnings:
70+
# now re-print all warnings to make sure they are seen
71+
print('-- warning raised by Python %s (%s) -- %s' % (ver_str, python, warning))
5772

5873
testall()

0 commit comments

Comments
 (0)