Skip to content

Commit 0e99dc8

Browse files
committed
Add a test
1 parent 2cd9c75 commit 0e99dc8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Lib/test/test_asyncio/test_tasks.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,32 @@ async def coro():
634634
self.assertEqual(actual,
635635
(asyncio.CancelledError, expected_args, 0))
636636

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+
637663
def test_cancel_with_message_before_starting_task(self):
638664
loop = asyncio.new_event_loop()
639665
self.set_event_loop(loop)

0 commit comments

Comments
 (0)