From bfed843312589dbf6b0ddfab490942e1f20e2382 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 26 Aug 2021 15:48:24 +0300 Subject: [PATCH 1/2] bpo-45011: Fix test_asyncio without C module _asyncio (GH-27968) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ɓukasz Langa (cherry picked from commit 7dc505b8655b3e48b93a4274dfd26e5856d9c64f) Co-authored-by: Serhiy Storchaka --- Lib/test/test_asyncio/functional.py | 5 ----- Lib/test/test_asyncio/test_futures.py | 2 ++ Lib/test/test_asyncio/test_sslproto.py | 3 +++ Lib/test/test_asyncio/test_tasks.py | 7 +++++-- .../next/Tests/2021-08-26-14-20-44.bpo-45011.mQZdXU.rst | 3 +++ 5 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2021-08-26-14-20-44.bpo-45011.mQZdXU.rst diff --git a/Lib/test/test_asyncio/functional.py b/Lib/test/test_asyncio/functional.py index 5cd0659387d843..70bc40892cca5a 100644 --- a/Lib/test/test_asyncio/functional.py +++ b/Lib/test/test_asyncio/functional.py @@ -29,10 +29,6 @@ def setUp(self): self.loop.set_exception_handler(self.loop_exception_handler) self.__unhandled_exceptions = [] - # Disable `_get_running_loop`. - self._old_get_running_loop = asyncio.events._get_running_loop - asyncio.events._get_running_loop = lambda: None - def tearDown(self): try: self.loop.close() @@ -43,7 +39,6 @@ def tearDown(self): self.fail('unexpected calls to loop.call_exception_handler()') finally: - asyncio.events._get_running_loop = self._old_get_running_loop asyncio.set_event_loop(None) self.loop = None diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py index ec00896cc620b3..c16bfc08a7abe7 100644 --- a/Lib/test/test_asyncio/test_futures.py +++ b/Lib/test/test_asyncio/test_futures.py @@ -876,6 +876,8 @@ def _get_future_cls(self): return futures._PyFuture +@unittest.skipUnless(hasattr(futures, '_CFuture'), + 'requires the C _asyncio module') class CFutureInheritanceTests(BaseFutureInheritanceTests, test_utils.TestCase): def _get_future_cls(self): diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py index 948820c82f3bfb..bc01a8bbf2d356 100644 --- a/Lib/test/test_asyncio/test_sslproto.py +++ b/Lib/test/test_asyncio/test_sslproto.py @@ -278,6 +278,7 @@ async def client(addr): # No garbage is left if SSL is closed uncleanly client_context = weakref.ref(client_context) + support.gc_collect() self.assertIsNone(client_context()) def test_create_connection_memory_leak(self): @@ -341,6 +342,7 @@ async def client(addr): # No garbage is left for SSL client from loop.create_connection, even # if user stores the SSLTransport in corresponding protocol instance client_context = weakref.ref(client_context) + support.gc_collect() self.assertIsNone(client_context()) def test_start_tls_client_buf_proto_1(self): @@ -640,6 +642,7 @@ async def client(addr): # The 10s handshake timeout should be cancelled to free related # objects without really waiting for 10s client_sslctx = weakref.ref(client_sslctx) + support.gc_collect() self.assertIsNone(client_sslctx()) def test_create_connection_ssl_slow_handshake(self): diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 01f62b7f408726..24d04feb950d38 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -3196,15 +3196,18 @@ class GenericTaskTests(test_utils.TestCase): def test_future_subclass(self): self.assertTrue(issubclass(asyncio.Task, asyncio.Future)) + @support.cpython_only def test_asyncio_module_compiled(self): # Because of circular imports it's easy to make _asyncio # module non-importable. This is a simple test that will # fail on systems where C modules were successfully compiled - # (hence the test for _functools), but _asyncio somehow didn't. + # (hence the test for _functools etc), but _asyncio somehow didn't. try: import _functools + import _json + import _pickle except ImportError: - pass + self.skipTest('C modules are not available') else: try: import _asyncio diff --git a/Misc/NEWS.d/next/Tests/2021-08-26-14-20-44.bpo-45011.mQZdXU.rst b/Misc/NEWS.d/next/Tests/2021-08-26-14-20-44.bpo-45011.mQZdXU.rst new file mode 100644 index 00000000000000..64e701e2f29f49 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2021-08-26-14-20-44.bpo-45011.mQZdXU.rst @@ -0,0 +1,3 @@ +Made tests relying on the :mod:`_asyncio` C extension module optional to +allow running on alternative Python implementations. Patch by Serhiy +Storchaka. From bdb756cd5c09d3bd627f1a32093027720bc27e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Thu, 26 Aug 2021 19:07:02 +0200 Subject: [PATCH 2/2] Ignore deprecation warnings from test_events --- Lib/test/test_asyncio/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_asyncio/__init__.py b/Lib/test/test_asyncio/__init__.py index 230c35cfcf12cf..4a7a868980d88b 100644 --- a/Lib/test/test_asyncio/__init__.py +++ b/Lib/test/test_asyncio/__init__.py @@ -28,6 +28,7 @@ def run(self, result, debug=False): ignore("asyncio.runners", like=r".*loop argument.*"), ignore("asyncio.subprocess", like=r".*loop argument.*"), ignore("asyncio.tasks", like=r".*loop argument.*"), + ignore("test.test_asyncio.test_events", like=r".*loop argument.*"), ignore("test.test_asyncio.test_queues", like=r".*loop argument.*"), ignore("test.test_asyncio.test_tasks", like=r".*loop argument.*"), }