@@ -673,6 +673,16 @@ def compiler(example):
673
673
raise
674
674
except BaseException :
675
675
exception = sys .exc_info ()
676
+ # On Python 2, the exception lives in sys.exc_info() as
677
+ # long we are in the same stack frame. To ensure that
678
+ # sig_occurred() works correctly, we need to clear the
679
+ # exception. This is not an issue on Python 3, where the
680
+ # exception is cleared as soon as we are outside of the
681
+ # "except" clause.
682
+ try :
683
+ sys .exc_clear ()
684
+ except AttributeError :
685
+ pass # Python 3
676
686
finally :
677
687
if self .debugger is not None :
678
688
self .debugger .set_continue () # ==== Example Finished ====
@@ -699,8 +709,7 @@ def compiler(example):
699
709
700
710
# The example raised an exception: check if it was expected.
701
711
else :
702
- exc_info = exception
703
- exc_msg = traceback .format_exception_only (* exc_info [:2 ])[- 1 ]
712
+ exc_msg = traceback .format_exception_only (* exception [:2 ])[- 1 ]
704
713
705
714
if six .PY3 and example .exc_msg is not None :
706
715
# On Python 3 the exception repr often includes the
@@ -709,7 +718,7 @@ def compiler(example):
709
718
# normalize Python 3 exceptions to match tests written to
710
719
# Python 2
711
720
# See https://trac.sagemath.org/ticket/24271
712
- exc_cls = exc_info [0 ]
721
+ exc_cls = exception [0 ]
713
722
exc_name = exc_cls .__name__
714
723
if exc_cls .__module__ :
715
724
exc_fullname = (exc_cls .__module__ + '.' +
@@ -736,7 +745,7 @@ def compiler(example):
736
745
break
737
746
738
747
if not quiet :
739
- got += doctest ._exception_traceback (exc_info )
748
+ got += doctest ._exception_traceback (exception )
740
749
741
750
# If `example.exc_msg` is None, then we weren't expecting
742
751
# an exception.
@@ -770,7 +779,7 @@ def compiler(example):
770
779
elif outcome is BOOM :
771
780
if not quiet :
772
781
self .report_unexpected_exception (out , test , example ,
773
- exc_info )
782
+ exception )
774
783
failures += 1
775
784
else :
776
785
assert False , ("unknown outcome" , outcome )
0 commit comments