]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
test: Fix some test interactions
authorBen Darnell <ben@bendarnell.com>
Fri, 31 Dec 2021 02:34:11 +0000 (21:34 -0500)
committerBen Darnell <ben@bendarnell.com>
Mon, 17 Jan 2022 00:21:31 +0000 (19:21 -0500)
These tests work in isolation but cause failures in the full suite
due to the leftover state of the asyncio event loop. Add cleanup to one
test and make another more tolerant of leftover state.

tornado/test/asyncio_test.py
tornado/test/ioloop_test.py
tornado/test/testing_test.py

index a6d36ff272025da6cd1f97e1e4766dac72f91bd8..bdb27e8293137db012189998c786ebec990258f1 100644 (file)
@@ -104,6 +104,9 @@ class AsyncIOLoopTest(AsyncTestCase):
             self.asyncio_loop.run_until_complete(native_coroutine_with_adapter2()),
             42,
         )
+        # I'm not entirely sure why this manual cleanup is necessary but without
+        # it we have at-a-distance failures in ioloop_test.TestIOLoopCurrent.
+        asyncio.set_event_loop(None)
 
 
 class LeakTest(unittest.TestCase):
index b3a223318a35c920637b7741aa8382fb06e3a5a9..c28516506ba7f9a4fde3b53b3da1d6d8630fb986 100644 (file)
@@ -420,7 +420,7 @@ class TestIOLoop(AsyncTestCase):
         # threads.
         def f():
             for i in range(10):
-                loop = IOLoop()
+                loop = IOLoop(make_current=False)
                 loop.close()
 
         yield gen.multi([self.io_loop.run_in_executor(None, f) for i in range(2)])
index 37cb24602a28b6421926a711b277834cbee5e9ce..a307c4bbf0a29857a4f15412fbe36467d6c1104b 100644 (file)
@@ -1,6 +1,7 @@
 from tornado import gen, ioloop
 from tornado.httpserver import HTTPServer
 from tornado.locks import Event
+from tornado.test.util import ignore_deprecation
 from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, bind_unused_port, gen_test
 from tornado.web import Application
 import asyncio
@@ -333,7 +334,11 @@ class GetNewIOLoopTest(AsyncTestCase):
     def setUp(self):
         # This simulates the effect of an asyncio test harness like
         # pytest-asyncio.
-        self.orig_loop = asyncio.get_event_loop()
+        with ignore_deprecation():
+            try:
+                self.orig_loop = asyncio.get_event_loop()
+            except RuntimeError:
+                self.orig_loop = None
         self.new_loop = asyncio.new_event_loop()
         asyncio.set_event_loop(self.new_loop)
         super().setUp()