@@ -573,6 +573,43 @@ def suppress_exc(*exc_details):
573573 self .assertIsInstance (inner_exc , ValueError )
574574 self .assertIsInstance (inner_exc .__context__ , ZeroDivisionError )
575575
576+ def test_exit_exception_non_suppressing (self ):
577+ # http://bugs.python.org/issue19092
578+ def raise_exc (exc ):
579+ raise exc
580+
581+ def suppress_exc (* exc_details ):
582+ return True
583+
584+ try :
585+ with ExitStack () as stack :
586+ stack .callback (lambda : None )
587+ stack .callback (raise_exc , IndexError )
588+ except Exception as exc :
589+ self .assertIsInstance (exc , IndexError )
590+ else :
591+ self .fail ("Expected IndexError, but no exception was raised" )
592+
593+ try :
594+ with ExitStack () as stack :
595+ stack .callback (raise_exc , KeyError )
596+ stack .push (suppress_exc )
597+ stack .callback (raise_exc , IndexError )
598+ except Exception as exc :
599+ self .assertIsInstance (exc , KeyError )
600+ else :
601+ self .fail ("Expected KeyError, but no exception was raised" )
602+
603+ def test_body_exception_suppress (self ):
604+ def suppress_exc (* exc_details ):
605+ return True
606+ try :
607+ with ExitStack () as stack :
608+ stack .push (suppress_exc )
609+ 1 / 0
610+ except IndexError as exc :
611+ self .fail ("Expected no exception, got IndexError" )
612+
576613 def test_exit_exception_chaining_suppress (self ):
577614 with ExitStack () as stack :
578615 stack .push (lambda * exc : True )
0 commit comments