@@ -796,8 +796,9 @@ class Example(object): pass
796796 self .assertIs (stack ._exit_callbacks [- 1 ], cm )
797797
798798 def test_dont_reraise_RuntimeError (self ):
799- """ https://bugs.python.org/issue27122"""
799+ # https://bugs.python.org/issue27122
800800 class UniqueException (Exception ): pass
801+ class UniqueRuntimeError (RuntimeError ): pass
801802
802803 @contextmanager
803804 def second ():
@@ -813,15 +814,20 @@ def first():
813814 except Exception as exc :
814815 raise exc
815816
816- # The RuntimeError should be caught by second()'s exception
817+ # The UniqueRuntimeError should be caught by second()'s exception
817818 # handler which chain raised a new UniqueException.
818819 with self .assertRaises (UniqueException ) as err_ctx :
819820 with ExitStack () as es_ctx :
820821 es_ctx .enter_context (second ())
821822 es_ctx .enter_context (first ())
822- raise RuntimeError ("please no infinite loop." )
823-
824- self .assertEqual (err_ctx .exception .args [0 ], "new exception" )
823+ raise UniqueRuntimeError ("please no infinite loop." )
824+
825+ exc = err_ctx .exception
826+ self .assertIsInstance (exc , UniqueException )
827+ self .assertIsInstance (exc .__context__ , UniqueRuntimeError )
828+ self .assertIsNone (exc .__context__ .__context__ )
829+ self .assertIsNone (exc .__context__ .__cause__ )
830+ self .assertIs (exc .__cause__ , exc .__context__ )
825831
826832
827833class TestRedirectStream :
0 commit comments