File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -634,6 +634,32 @@ async def coro():
634
634
self .assertEqual (actual ,
635
635
(asyncio .CancelledError , expected_args , 0 ))
636
636
637
+ def test_cancellation_exception_context (self ):
638
+ loop = asyncio .new_event_loop ()
639
+ self .set_event_loop (loop )
640
+
641
+ async def sleep ():
642
+ await asyncio .sleep (10 )
643
+
644
+ async def coro ():
645
+ inner_task = self .new_task (loop , sleep ())
646
+ await asyncio .sleep (0 )
647
+ loop .call_soon (inner_task .cancel , 'msg' )
648
+ try :
649
+ await inner_task
650
+ except asyncio .CancelledError as ex :
651
+ raise ValueError ("cancelled" ) from ex
652
+
653
+ task = self .new_task (loop , coro ())
654
+ with self .assertRaises (ValueError ) as cm :
655
+ loop .run_until_complete (task )
656
+ exc = cm .exception
657
+ self .assertEqual (exc .args , ('cancelled' ,))
658
+
659
+ actual = get_innermost_context (exc )
660
+ self .assertEqual (actual ,
661
+ (asyncio .CancelledError , ('msg' ,), 1 ))
662
+
637
663
def test_cancel_with_message_before_starting_task (self ):
638
664
loop = asyncio .new_event_loop ()
639
665
self .set_event_loop (loop )
You can’t perform that action at this time.
0 commit comments