summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
diff options
context:
space:
mode:
authorBar Harel <bar.harel@biocatch.com>2021-08-16 08:21:08 (GMT)
committerGitHub <noreply@github.com>2021-08-16 08:21:08 (GMT)
commit2cb1a6806c0cefab0c3a40fdd428a89a4392570e (patch)
tree86ef17b88214f75335bab94a7c28b6c89ad9846f /Lib/unittest/test
parentad0a8a9c629a7a0fa306fbdf019be63c701a8028 (diff)
downloadcpython-2cb1a6806c0cefab0c3a40fdd428a89a4392570e.zip
cpython-2cb1a6806c0cefab0c3a40fdd428a89a4392570e.tar.gz
cpython-2cb1a6806c0cefab0c3a40fdd428a89a4392570e.tar.bz2
bpo-44911: Fixed IsolatedAsyncioTestCase from throwing an exception on leaked tasks (GH-27765)
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/test_async_case.py20
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 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__":