]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
testing: Deprecate AsyncTestCase
authorBen Darnell <ben@bendarnell.com>
Tue, 28 Dec 2021 20:56:33 +0000 (15:56 -0500)
committerBen Darnell <ben@bendarnell.com>
Sun, 16 Jan 2022 21:49:19 +0000 (16:49 -0500)
The interfaces defined by this class rely on an event loop being
"current" even though it is not running; this is incompatible with
the future of the asyncio module.

It's too big a task to rewrite all the tests right now, so just
swallow deprecation warnings for "no current event loop".

tornado/testing.py

index cdea88ee0a20adc65f3bcafe0602162f869e3c37..45e72c8b31fc1d0ce1a0b1bae8fedf2a53619dfb 100644 (file)
@@ -161,6 +161,17 @@ class AsyncTestCase(unittest.TestCase):
                 response = self.wait()
                 # Test contents of response
                 self.assertIn("FriendFeed", response.body)
+
+    .. deprecated:: 6.2
+
+       AsyncTestCase and AsyncHTTPTestCase are deprecated due to changes
+       in future versions of Python (after 3.10). The interfaces used
+       in this class are incompatible with the deprecation and intended
+       removal of certain methods related to the idea of a "current"
+       event loop while no event loop is actually running. Use
+       `unittest.IsolatedAsyncioTestCase` instead. Note that this class
+       does not emit DeprecationWarnings until better migration guidance
+       can be provided.
     """
 
     def __init__(self, methodName: str = "runTest") -> None:
@@ -181,6 +192,13 @@ 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\..*",
+        )
         super().setUp()
         # NOTE: this code attempts to navigate deprecation warnings introduced
         # in Python 3.10. The idea of an implicit current event loop is