Skip to content

Commit

Permalink
[mypyc] Improve failure reporting in default run test driver (#15563)
Browse files Browse the repository at this point in the history
Fix stdout flushing to avoid empty lines getting out of alignment with
the rest of the output.

Display the name of a failed test function, since it's sometimes not
visible in the traceback (at least if something incorrectly propagates exceptions).
  • Loading branch information
JukkaL authored Jul 1, 2023
1 parent 3730899 commit 19c5d5f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mypyc/test-data/driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
try:
test_func()
except Exception as e:
failures.append(sys.exc_info())
failures.append((name, sys.exc_info()))

if failures:
from traceback import print_exception, format_tb
Expand All @@ -32,12 +32,17 @@ def extract_line(tb):
return m.group(1)

# Sort failures by line number of test function.
failures = sorted(failures, key=lambda e: extract_line(e[2]))
failures = sorted(failures, key=lambda e: extract_line(e[1][2]))

# If there are multiple failures, print stack traces of all but the final failure.
for e in failures[:-1]:
for name, e in failures[:-1]:
print(f'<< {name} >>')
sys.stdout.flush()
print_exception(*e)
print()
sys.stdout.flush()

# Raise exception for the last failure. Test runner will show the traceback.
raise failures[-1][1]
print(f'<< {failures[-1][0]} >>')
sys.stdout.flush()
raise failures[-1][1][1]

0 comments on commit 19c5d5f

Please sign in to comment.