diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-08-16 02:54:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-16 02:54:58 -0700 |
commit | 8516ca500eb45ecf997a471f003df02a9eb767ce (patch) | |
tree | 25c97a453f062a430139ac47ba5eecb474e7b89c /Lib/unittest/test/test_async_case.py | |
parent | 1960409a6dcbd1e3527f02b523bd27df9086dd77 (diff) | |
download | cpython-git-8516ca500eb45ecf997a471f003df02a9eb767ce.tar.gz |
bpo-44911: Fixed IsolatedAsyncioTestCase from throwing an exception on leaked tasks (GH-27765)
(cherry picked from commit 2cb1a6806c0cefab0c3a40fdd428a89a4392570e)
Co-authored-by: Bar Harel <bar.harel@biocatch.com>
Diffstat (limited to 'Lib/unittest/test/test_async_case.py')
-rw-r--r-- | Lib/unittest/test/test_async_case.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_async_case.py b/Lib/unittest/test/test_async_case.py index d01864b693..6e48b9e4bf 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__": |