]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 16 Dec 2020 17:57:23 +0000 (09:57 -0800)
committerGitHub <noreply@github.com>
Wed, 16 Dec 2020 17:57:23 +0000 (09:57 -0800)
(cherry picked from commit 8374d2ee1589791be8892b00f4bbf8121dde24bd)

Co-authored-by: Lisa Roach <lisaroach14@gmail.com>
Lib/unittest/async_case.py
Lib/unittest/test/test_async_case.py
Misc/NEWS.d/next/Library/2020-10-11-21-43-03.bpo-39101.-I49Pm.rst [new file with mode: 0644]

index 1bc1312c8c2ee9cba2491d66a44b157a37c3ab9e..520213c37275555f29d37bf361202fb72d1af4ec 100644 (file)
@@ -102,9 +102,9 @@ class IsolatedAsyncioTestCase(TestCase):
                 ret = await awaitable
                 if not fut.cancelled():
                     fut.set_result(ret)
-            except asyncio.CancelledError:
+            except (SystemExit, KeyboardInterrupt):
                 raise
-            except Exception as ex:
+            except (BaseException, asyncio.CancelledError) as ex:
                 if not fut.cancelled():
                     fut.set_exception(ex)
 
index 2db441da202a0183d91381bb7c15eb9c345c6cad..d01864b6936ca8d2ec5d47e2c2b6bd7fb1ab092f 100644 (file)
@@ -190,6 +190,33 @@ class TestAsyncCase(unittest.TestCase):
                                   'async_cleanup 2',
                                   'sync_cleanup 1'])
 
+    def test_base_exception_from_async_method(self):
+        events = []
+        class Test(unittest.IsolatedAsyncioTestCase):
+            async def test_base(self):
+                events.append("test_base")
+                raise BaseException()
+                events.append("not it")
+
+            async def test_no_err(self):
+                events.append("test_no_err")
+
+            async def test_cancel(self):
+                raise asyncio.CancelledError()
+
+        test = Test("test_base")
+        output = test.run()
+        self.assertFalse(output.wasSuccessful())
+
+        test = Test("test_no_err")
+        test.run()
+        self.assertEqual(events, ['test_base', 'test_no_err'])
+
+        test = Test("test_cancel")
+        output = test.run()
+        self.assertFalse(output.wasSuccessful())
+
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2020-10-11-21-43-03.bpo-39101.-I49Pm.rst b/Misc/NEWS.d/next/Library/2020-10-11-21-43-03.bpo-39101.-I49Pm.rst
new file mode 100644 (file)
index 0000000..a571e83
--- /dev/null
@@ -0,0 +1 @@
+Fixed tests using IsolatedAsyncioTestCase from hanging on BaseExceptions.
\ No newline at end of file