[Python-checkins] bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)

miss-islington webhook-mailer at python.org
Wed Dec 16 12:57:31 EST 2020


https://github.com/python/cpython/commit/d549d0b5575b390431b7b26999151f79f74d4516
commit: d549d0b5575b390431b7b26999151f79f74d4516
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2020-12-16T09:57:23-08:00
summary:

bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)

(cherry picked from commit 8374d2ee1589791be8892b00f4bbf8121dde24bd)

Co-authored-by: Lisa Roach <lisaroach14 at gmail.com>

files:
A Misc/NEWS.d/next/Library/2020-10-11-21-43-03.bpo-39101.-I49Pm.rst
M Lib/unittest/async_case.py
M Lib/unittest/test/test_async_case.py

diff --git a/Lib/unittest/async_case.py b/Lib/unittest/async_case.py
index 1bc1312c8c2ee..520213c372755 100644
--- a/Lib/unittest/async_case.py
+++ b/Lib/unittest/async_case.py
@@ -102,9 +102,9 @@ async def _asyncioLoopRunner(self, fut):
                 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)
 
diff --git a/Lib/unittest/test/test_async_case.py b/Lib/unittest/test/test_async_case.py
index 2db441da202a0..d01864b6936ca 100644
--- a/Lib/unittest/test/test_async_case.py
+++ b/Lib/unittest/test/test_async_case.py
@@ -190,6 +190,33 @@ async def on_async_cleanup(self, val):
                                   '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
index 0000000000000..a571e8343cde1
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-10-11-21-43-03.bpo-39101.-I49Pm.rst
@@ -0,0 +1 @@
+Fixed tests using IsolatedAsyncioTestCase from hanging on BaseExceptions.
\ No newline at end of file



More information about the Python-checkins mailing list