]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-45011: Fix test_asyncio without C module _asyncio (GH-27968) (GH-27970)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 26 Aug 2021 17:56:50 +0000 (10:56 -0700)
committerGitHub <noreply@github.com>
Thu, 26 Aug 2021 17:56:50 +0000 (19:56 +0200)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
(cherry picked from commit 7dc505b8655b3e48b93a4274dfd26e5856d9c64f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_asyncio/__init__.py
Lib/test/test_asyncio/functional.py
Lib/test/test_asyncio/test_futures.py
Lib/test/test_asyncio/test_sslproto.py
Lib/test/test_asyncio/test_tasks.py
Misc/NEWS.d/next/Tests/2021-08-26-14-20-44.bpo-45011.mQZdXU.rst [new file with mode: 0644]

index 230c35cfcf12cfbd5ecf2cccdb5c4a3ac793ab45..4a7a868980d88be11d6d1b8e75fb0f7ababb2c02 100644 (file)
@@ -28,6 +28,7 @@ class AsyncioTestSuite(unittest.TestSuite):
             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.*"),
         }
index 5cd0659387d843ba50fcb93c43dc1a33b9aea424..70bc40892cca5a08421f221ecc584f90d2eb9e7d 100644 (file)
@@ -29,10 +29,6 @@ class FunctionalTestCaseMixin:
         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 @@ class FunctionalTestCaseMixin:
                 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
 
index ec00896cc620b3ff07e182d6fa8ee3fe06bfc885..c16bfc08a7abe7bf23884023e2906f4b1960b7fb 100644 (file)
@@ -876,6 +876,8 @@ class PyFutureInheritanceTests(BaseFutureInheritanceTests,
         return futures._PyFuture
 
 
+@unittest.skipUnless(hasattr(futures, '_CFuture'),
+                     'requires the C _asyncio module')
 class CFutureInheritanceTests(BaseFutureInheritanceTests,
                               test_utils.TestCase):
     def _get_future_cls(self):
index 948820c82f3bfb6c27dfff2814c66776c69422cd..bc01a8bbf2d3563e4a2a55aee14132e4ad50c834 100644 (file)
@@ -278,6 +278,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
 
         # 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 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
         # 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 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
         # 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):
index 01f62b7f408726435ce538b5cd4ecab8e741a696..24d04feb950d38ea6b581cce5aefb428ebc5c781 100644 (file)
@@ -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 (file)
index 0000000..64e701e
--- /dev/null
@@ -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.