From 9ab9523ccfd2d5f38a7dd9d62b678ab8f8210547 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Sat, 1 Jul 2023 12:14:55 +0100 Subject: [PATCH 1/2] Fix stdout flushing in default run test driver --- mypyc/test-data/driver/driver.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mypyc/test-data/driver/driver.py b/mypyc/test-data/driver/driver.py index 6717f402f72d..caa7bb94b990 100644 --- a/mypyc/test-data/driver/driver.py +++ b/mypyc/test-data/driver/driver.py @@ -38,6 +38,7 @@ def extract_line(tb): for e in failures[:-1]: print_exception(*e) print() + sys.stdout.flush() # Raise exception for the last failure. Test runner will show the traceback. raise failures[-1][1] From bdb3418f07acb97eea4eafd0e5abcc9cd4527d30 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Sat, 1 Jul 2023 14:17:44 +0100 Subject: [PATCH 2/2] [mypyc] Display name of failed test in default test driver Sometimes the traceback was truncated and the failed test method wasn't visible. --- mypyc/test-data/driver/driver.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mypyc/test-data/driver/driver.py b/mypyc/test-data/driver/driver.py index caa7bb94b990..c9d179224a30 100644 --- a/mypyc/test-data/driver/driver.py +++ b/mypyc/test-data/driver/driver.py @@ -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 @@ -32,13 +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]