Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 1 addition & 1 deletion Lib/unittest/async_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async def _asyncioLoopRunner(self, fut):
fut.set_result(ret)
except asyncio.CancelledError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add except (SystemExit, KeyboardInterrupt): raise before handling the BaseException.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1st1 this will still leave SystemExit and KeyboardInterrupt hanging if they are raised, I think they should be handled along with the BaseException.

raise
except Exception as ex:
except BaseException as ex:
if not fut.cancelled():
fut.set_exception(ex)

Expand Down
18 changes: 18 additions & 0 deletions Lib/unittest/test/test_async_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,24 @@ 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_a(self):
events.append("test_a")
raise BaseException()
events.append("not it")

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

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

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

if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed tests using IsolatedAsyncioTestCase from hanging on BaseExceptions.