Skip to content

Commit

Permalink
Re-print test warnings after tests have ran (issue #458).
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Crozzers committed Jul 19, 2022
1 parent 88d5262 commit faee13e
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions test/testall.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,34 @@ def _gen_pythons():
yield ver, python

def testall():
all_warnings = []
for ver, python in _gen_pythons():
if ver < (3, 5):
# Don't support Python < 3.5
continue
ver_str = "%s.%s" % ver
print("-- test with Python %s (%s)" % (ver_str, python))
assert ' ' not in python

proc = subprocess.Popen(
"MACOSX_DEPLOYMENT_TARGET= %s test.py -- -knownfailure" % python,
shell=True
# pass "-u" option to force unbuffered output
"MACOSX_DEPLOYMENT_TARGET= %s -u test.py -- -knownfailure" % python,
shell=True, stderr=subprocess.PIPE
)
rv = proc.wait()
if rv:
sys.exit(os.WEXITSTATUS(rv))

while proc.poll() is None:
# capture and re-print stderr while process is running
line = proc.stderr.readline().decode().strip()
print(line, file=sys.stderr)
if 'WARNING:test:' in line:
# if stderr contains a warning, save this for later
all_warnings.append((python, ver_str, line))

if proc.returncode:
sys.exit(os.WEXITSTATUS(proc.returncode))

for python, ver_str, warning in all_warnings:
# now re-print all warnings to make sure they are seen
print('-- warning raised by Python %s (%s) -- %s' % (ver_str, python, warning))

testall()

0 comments on commit faee13e

Please sign in to comment.