]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Don't try to restore the previous event loop in AsyncTestCase
authorThomas Kluyver <thomas@kluyver.me.uk>
Thu, 16 Feb 2023 13:16:36 +0000 (13:16 +0000)
committerThomas Kluyver <thomas@kluyver.me.uk>
Thu, 16 Feb 2023 13:16:36 +0000 (13:16 +0000)
tornado/test/testing_test.py
tornado/testing.py

index ca48d567a2610fbba16a35e12cb8de8960f5eb7d..cdbf1a3ae778291196060d08caecf4ad2880995b 100644 (file)
@@ -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()
index 0ef097656ab8bd9059c548c6802f8c806cfd3194..68459f297a0f399b01dd89e6446200a2ab55969e 100644 (file)
@@ -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