diff options
Diffstat (limited to 'Lib/unittest')
-rw-r--r-- | Lib/unittest/async_case.py | 2 | ||||
-rw-r--r-- | Lib/unittest/test/test_async_case.py | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/Lib/unittest/async_case.py b/Lib/unittest/async_case.py index 520213c..86ed704 100644 --- a/Lib/unittest/async_case.py +++ b/Lib/unittest/async_case.py @@ -135,7 +135,7 @@ class IsolatedAsyncioTestCase(TestCase): task.cancel() loop.run_until_complete( - asyncio.gather(*to_cancel, loop=loop, return_exceptions=True)) + asyncio.gather(*to_cancel, return_exceptions=True)) for task in to_cancel: if task.cancelled(): diff --git a/Lib/unittest/test/test_async_case.py b/Lib/unittest/test/test_async_case.py index d01864b..6e48b9e 100644 --- a/Lib/unittest/test/test_async_case.py +++ b/Lib/unittest/test/test_async_case.py @@ -216,6 +216,26 @@ class TestAsyncCase(unittest.TestCase): output = test.run() self.assertFalse(output.wasSuccessful()) + def test_cancellation_hanging_tasks(self): + cancelled = False + class Test(unittest.IsolatedAsyncioTestCase): + async def test_leaking_task(self): + async def coro(): + nonlocal cancelled + try: + await asyncio.sleep(1) + except asyncio.CancelledError: + cancelled = True + raise + + # Leave this running in the background + asyncio.create_task(coro()) + + test = Test("test_leaking_task") + output = test.run() + self.assertTrue(cancelled) + + if __name__ == "__main__": |