summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/unittest/async_case.py4
-rw-r--r--Lib/unittest/test/test_async_case.py27
2 files changed, 29 insertions, 2 deletions
diff --git a/Lib/unittest/async_case.py b/Lib/unittest/async_case.py
index 1bc1312..520213c 100644
--- a/Lib/unittest/async_case.py
+++ b/Lib/unittest/async_case.py
@@ -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)
diff --git a/Lib/unittest/test/test_async_case.py b/Lib/unittest/test/test_async_case.py
index 2db441d..d01864b 100644
--- a/Lib/unittest/test/test_async_case.py
+++ b/Lib/unittest/test/test_async_case.py
@@ -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()