]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
testing: Limit silence of deprecation warnings 3232/head
authorBen Darnell <ben@bendarnell.com>
Thu, 16 Feb 2023 22:20:34 +0000 (22:20 +0000)
committerBen Darnell <ben@bendarnell.com>
Fri, 17 Feb 2023 03:18:16 +0000 (03:18 +0000)
Only do it on the specific versions that had the problematic warnings.

Also deprecate get_new_ioloop.

tornado/test/asyncio_test.py
tornado/testing.py

index 3a08ea494ad2c51f561b5d1e3bf94cbfa0d9a2de..348c0cebb1b45a8c8bed44232c7c40a47f68e09c 100644 (file)
@@ -26,10 +26,6 @@ from tornado.testing import AsyncTestCase, gen_test
 
 
 class AsyncIOLoopTest(AsyncTestCase):
-    def get_new_ioloop(self):
-        io_loop = AsyncIOLoop(make_current=False)
-        return io_loop
-
     @property
     def asyncio_loop(self):
         return self.io_loop.asyncio_loop  # type: ignore
index 68459f297a0f399b01dd89e6446200a2ab55969e..9bfadf45ed8a83ac6ff477d25930501db9243d7d 100644 (file)
@@ -135,7 +135,8 @@ class AsyncTestCase(unittest.TestCase):
 
     By default, a new `.IOLoop` is constructed for each test and is available
     as ``self.io_loop``.  If the code being tested requires a
-    global `.IOLoop`, subclasses should override `get_new_ioloop` to return it.
+    reused global `.IOLoop`, subclasses should override `get_new_ioloop` to return it,
+    although this is deprecated as of Tornado 6.3.
 
     The `.IOLoop`'s ``start`` and ``stop`` methods should not be
     called directly.  Instead, use `self.stop <stop>` and `self.wait
@@ -182,14 +183,20 @@ class AsyncTestCase(unittest.TestCase):
         self._test_generator = None  # type: Optional[Union[Generator, Coroutine]]
 
     def setUp(self) -> None:
-        setup_with_context_manager(self, warnings.catch_warnings())
-        warnings.filterwarnings(
-            "ignore",
-            message="There is no current event loop",
-            category=DeprecationWarning,
-            module=r"tornado\..*",
-        )
+        py_ver = sys.version_info
+        if ((3, 10, 0) <= py_ver < (3, 10, 9)) or ((3, 11, 0) <= py_ver <= (3, 11, 1)):
+            # Early releases in the Python 3.10 and 3.1 series had deprecation
+            # warnings that were later reverted; we must suppress them here.
+            setup_with_context_manager(self, warnings.catch_warnings())
+            warnings.filterwarnings(
+                "ignore",
+                message="There is no current event loop",
+                category=DeprecationWarning,
+                module=r"tornado\..*",
+            )
         super().setUp()
+        if type(self).get_new_ioloop is not AsyncTestCase.get_new_ioloop:
+            warnings.warn("get_new_ioloop is deprecated", DeprecationWarning)
         self.io_loop = self.get_new_ioloop()
         asyncio.set_event_loop(self.io_loop.asyncio_loop)  # type: ignore[attr-defined]
 
@@ -250,6 +257,9 @@ class AsyncTestCase(unittest.TestCase):
         singletons using the default `.IOLoop`) or if a per-test event
         loop is being provided by another system (such as
         ``pytest-asyncio``).
+
+        .. deprecated:: 6.3
+           This method will be removed in Tornado 7.0.
         """
         return IOLoop(make_current=False)