MCPcopy Index your code
hub / github.com/python/cpython / test_cancel_at_end

Method test_cancel_at_end

Lib/test/test_asyncio/test_tasks.py:977–994  ·  view source on GitHub ↗

coroutine end right after task is cancelled

(self)

Source from the content-addressed store, hash-verified

975 self.assertFalse(t.cancel())
976
977 def test_cancel_at_end(self):
978 """coroutine end right after task is cancelled"""
979 loop = asyncio.new_event_loop()
980 self.set_event_loop(loop)
981
982 async def task():
983 t.cancel()
984 self.assertTrue(t._must_cancel) # White-box test.
985 return 12
986
987 t = self.new_task(loop, task())
988 self.assertFalse(t.cancelled())
989 self.assertRaises(
990 asyncio.CancelledError, loop.run_until_complete, t)
991 self.assertTrue(t.done())
992 self.assertTrue(t.cancelled())
993 self.assertFalse(t._must_cancel) # White-box test.
994 self.assertFalse(t.cancel())
995
996 def test_cancel_awaited_task(self):
997 # This tests for a relatively rare condition when

Callers

nothing calls this directly

Calls 10

new_taskMethod · 0.95
taskFunction · 0.85
assertFalseMethod · 0.80
assertTrueMethod · 0.80
new_event_loopMethod · 0.45
set_event_loopMethod · 0.45
cancelledMethod · 0.45
assertRaisesMethod · 0.45
doneMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected