From: Thomas Kluyver Date: Thu, 16 Feb 2023 13:16:36 +0000 (+0000) Subject: Don't try to restore the previous event loop in AsyncTestCase X-Git-Tag: v6.3.0b1~8^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb9229d8824cad89f7a4ce2e95e07d22b89079e9;p=thirdparty%2Ftornado.git Don't try to restore the previous event loop in AsyncTestCase --- diff --git a/tornado/test/testing_test.py b/tornado/test/testing_test.py index ca48d567a..cdbf1a3ae 100644 --- a/tornado/test/testing_test.py +++ b/tornado/test/testing_test.py @@ -342,33 +342,5 @@ class GenTest(AsyncTestCase): self.finished = True -class GetNewIOLoopTest(AsyncTestCase): - def get_new_ioloop(self): - # Use the current loop instead of creating a new one here. - return ioloop.IOLoop.current() - - def setUp(self): - # This simulates the effect of an asyncio test harness like - # pytest-asyncio. - with ignore_deprecation(): - try: - self.orig_loop = asyncio.get_event_loop() - except RuntimeError: - self.orig_loop = None # type: ignore[assignment] - self.new_loop = asyncio.new_event_loop() - asyncio.set_event_loop(self.new_loop) - super().setUp() - - def tearDown(self): - super().tearDown() - # AsyncTestCase must not affect the existing asyncio loop. - self.assertFalse(asyncio.get_event_loop().is_closed()) - asyncio.set_event_loop(self.orig_loop) - self.new_loop.close() - - def test_loop(self): - self.assertIs(self.io_loop.asyncio_loop, self.new_loop) # type: ignore - - if __name__ == "__main__": unittest.main() diff --git a/tornado/testing.py b/tornado/testing.py index 0ef097656..68459f297 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -190,10 +190,6 @@ class AsyncTestCase(unittest.TestCase): module=r"tornado\..*", ) super().setUp() - try: - self._prev_aio_loop = asyncio.get_event_loop() - except RuntimeError: - self._prev_aio_loop = None # type: ignore[assignment] self.io_loop = self.get_new_ioloop() asyncio.set_event_loop(self.io_loop.asyncio_loop) # type: ignore[attr-defined] @@ -230,7 +226,7 @@ class AsyncTestCase(unittest.TestCase): # Clean up Subprocess, so it can be used again with a new ioloop. Subprocess.uninitialize() - asyncio.set_event_loop(self._prev_aio_loop) + asyncio.set_event_loop(None) if not isinstance(self.io_loop, _NON_OWNED_IOLOOPS): # Try to clean up any file descriptors left open in the ioloop. # This avoids leaks, especially when tests are run repeatedly