From 9cbfb7308cc901409e81cc7d3cc7edf17eacd113 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Fri, 16 Dec 2022 15:07:30 -0500 Subject: [PATCH] test: Catch error from get_event_loop in tearDown --- tornado/test/asyncio_test.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tornado/test/asyncio_test.py b/tornado/test/asyncio_test.py index 551a9a8d5..c33d7256b 100644 --- a/tornado/test/asyncio_test.py +++ b/tornado/test/asyncio_test.py @@ -119,7 +119,13 @@ class LeakTest(unittest.TestCase): asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy()) def tearDown(self): - asyncio.get_event_loop_policy().get_event_loop().close() + try: + loop = asyncio.get_event_loop_policy().get_event_loop() + except Exception: + # We may not have a current event loop at this point. + pass + else: + loop.close() asyncio.set_event_loop_policy(self.orig_policy) def test_ioloop_close_leak(self): -- 2.47.2