@@ -108,6 +108,8 @@ def _test():
108
108
from _colorize import ANSIColors , can_colorize
109
109
110
110
111
+ __unittest = True
112
+
111
113
class TestResults (namedtuple ('TestResults' , 'failed attempted' )):
112
114
def __new__ (cls , failed , attempted , * , skipped = 0 ):
113
115
results = super ().__new__ (cls , failed , attempted )
@@ -1395,11 +1397,12 @@ def __run(self, test, compileflags, out):
1395
1397
exec (compile (example .source , filename , "single" ,
1396
1398
compileflags , True ), test .globs )
1397
1399
self .debugger .set_continue () # ==== Example Finished ====
1398
- exception = None
1400
+ exc_info = None
1399
1401
except KeyboardInterrupt :
1400
1402
raise
1401
1403
except :
1402
- exception = sys .exc_info ()
1404
+ exc_info = sys .exc_info ()
1405
+ exc_info = (* exc_info [:2 ], exc_info [2 ].tb_next )
1403
1406
self .debugger .set_continue () # ==== Example Finished ====
1404
1407
1405
1408
got = self ._fakeout .getvalue () # the actual output
@@ -1408,21 +1411,21 @@ def __run(self, test, compileflags, out):
1408
1411
1409
1412
# If the example executed without raising any exceptions,
1410
1413
# verify its output.
1411
- if exception is None :
1414
+ if exc_info is None :
1412
1415
if check (example .want , got , self .optionflags ):
1413
1416
outcome = SUCCESS
1414
1417
1415
1418
# The example raised an exception: check if it was expected.
1416
1419
else :
1417
- formatted_ex = traceback .format_exception_only (* exception [:2 ])
1418
- if issubclass (exception [0 ], SyntaxError ):
1420
+ formatted_ex = traceback .format_exception_only (* exc_info [:2 ])
1421
+ if issubclass (exc_info [0 ], SyntaxError ):
1419
1422
# SyntaxError / IndentationError is special:
1420
1423
# we don't care about the carets / suggestions / etc
1421
1424
# We only care about the error message and notes.
1422
1425
# They start with `SyntaxError:` (or any other class name)
1423
1426
exception_line_prefixes = (
1424
- f"{ exception [0 ].__qualname__ } :" ,
1425
- f"{ exception [0 ].__module__ } .{ exception [0 ].__qualname__ } :" ,
1427
+ f"{ exc_info [0 ].__qualname__ } :" ,
1428
+ f"{ exc_info [0 ].__module__ } .{ exc_info [0 ].__qualname__ } :" ,
1426
1429
)
1427
1430
exc_msg_index = next (
1428
1431
index
@@ -1433,7 +1436,7 @@ def __run(self, test, compileflags, out):
1433
1436
1434
1437
exc_msg = "" .join (formatted_ex )
1435
1438
if not quiet :
1436
- got += _exception_traceback (exception )
1439
+ got += _exception_traceback (exc_info )
1437
1440
1438
1441
# If `example.exc_msg` is None, then we weren't expecting
1439
1442
# an exception.
@@ -1462,7 +1465,7 @@ def __run(self, test, compileflags, out):
1462
1465
elif outcome is BOOM :
1463
1466
if not quiet :
1464
1467
self .report_unexpected_exception (out , test , example ,
1465
- exception )
1468
+ exc_info )
1466
1469
failures += 1
1467
1470
else :
1468
1471
assert False , ("unknown outcome" , outcome )
@@ -2324,7 +2327,7 @@ def runTest(self):
2324
2327
sys .stdout = old
2325
2328
2326
2329
if results .failed :
2327
- raise self .failureException (self .format_failure (new .getvalue ()))
2330
+ raise self .failureException (self .format_failure (new .getvalue (). rstrip ( ' \n ' ) ))
2328
2331
2329
2332
def format_failure (self , err ):
2330
2333
test = self ._dt_test
0 commit comments