Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Moves System and Keyboard exception to use raise, Cancelled does not.
  • Loading branch information
lisroach committed Oct 24, 2020
commit 1e268cb751d8350d754aa1a887524e3d146617cd
4 changes: 2 additions & 2 deletions Lib/unittest/async_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 BaseException as ex:
except (BaseException, asyncio.CancelledError) as ex:
if not fut.cancelled():
fut.set_exception(ex)

Expand Down
23 changes: 16 additions & 7 deletions Lib/unittest/test/test_async_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,30 @@ async def on_async_cleanup(self, val):
def test_base_exception_from_async_method(self):
events = []
class Test(unittest.IsolatedAsyncioTestCase):
async def test_a(self):
events.append("test_a")
async def test_base(self):
events.append("test_base")
raise BaseException()
events.append("not it")

async def test_b(self):
events.append("test_b")
async def test_no_err(self):
events.append("test_no_err")

test = Test("test_a")
async def test_cancel(self):
raise asyncio.CancelledError()

test = Test("test_base")
output = test.run()
self.assertFalse(output.wasSuccessful())

test = Test("test_b")
test = Test("test_no_err")
test.run()
self.assertEqual(events, ['test_a', 'test_b'])
self.assertEqual(events, ['test_base', 'test_no_err'])

test = Test("test_cancel")
output = test.run()
self.assertFalse(output.wasSuccessful())



if __name__ == "__main__":
unittest.main()