Skip to content

Commit 19c5d5f

Browse files
authored
[mypyc] Improve failure reporting in default run test driver (#15563)
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).
1 parent 3730899 commit 19c5d5f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

mypyc/test-data/driver/driver.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
try:
1919
test_func()
2020
except Exception as e:
21-
failures.append(sys.exc_info())
21+
failures.append((name, sys.exc_info()))
2222

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

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

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

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

0 commit comments

Comments
 (0)