Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mypyc] Improve failure reporting in default run test driver #15563

Merged
merged 2 commits into from
Jul 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]