From: Ben Darnell Date: Fri, 31 Dec 2021 02:34:11 +0000 (-0500) Subject: test: Fix some test interactions X-Git-Tag: v6.2.0b1~36^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5083089eff7285d68a5eb23ed75b1fd10eee7865;p=thirdparty%2Ftornado.git test: Fix some test interactions 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. --- diff --git a/tornado/test/asyncio_test.py b/tornado/test/asyncio_test.py index a6d36ff27..bdb27e829 100644 --- a/tornado/test/asyncio_test.py +++ b/tornado/test/asyncio_test.py @@ -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): diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index b3a223318..c28516506 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -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)]) diff --git a/tornado/test/testing_test.py b/tornado/test/testing_test.py index 37cb24602..a307c4bbf 100644 --- a/tornado/test/testing_test.py +++ b/tornado/test/testing_test.py @@ -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()