Skip to content

Commit 970533e

Browse files
[3.9] bpo-45011: Fix test_asyncio without C module _asyncio (GH-27968) (GH-27970)
Co-authored-by: Łukasz Langa <[email protected]> (cherry picked from commit 7dc505b) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 2cdbd3b commit 970533e

File tree

6 files changed

+14
-7
lines changed

6 files changed

+14
-7
lines changed

Lib/test/test_asyncio/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def run(self, result, debug=False):
2828
ignore("asyncio.runners", like=r".*loop argument.*"),
2929
ignore("asyncio.subprocess", like=r".*loop argument.*"),
3030
ignore("asyncio.tasks", like=r".*loop argument.*"),
31+
ignore("test.test_asyncio.test_events", like=r".*loop argument.*"),
3132
ignore("test.test_asyncio.test_queues", like=r".*loop argument.*"),
3233
ignore("test.test_asyncio.test_tasks", like=r".*loop argument.*"),
3334
}

Lib/test/test_asyncio/functional.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ def setUp(self):
2929
self.loop.set_exception_handler(self.loop_exception_handler)
3030
self.__unhandled_exceptions = []
3131

32-
# Disable `_get_running_loop`.
33-
self._old_get_running_loop = asyncio.events._get_running_loop
34-
asyncio.events._get_running_loop = lambda: None
35-
3632
def tearDown(self):
3733
try:
3834
self.loop.close()
@@ -43,7 +39,6 @@ def tearDown(self):
4339
self.fail('unexpected calls to loop.call_exception_handler()')
4440

4541
finally:
46-
asyncio.events._get_running_loop = self._old_get_running_loop
4742
asyncio.set_event_loop(None)
4843
self.loop = None
4944

Lib/test/test_asyncio/test_futures.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,8 @@ def _get_future_cls(self):
876876
return futures._PyFuture
877877

878878

879+
@unittest.skipUnless(hasattr(futures, '_CFuture'),
880+
'requires the C _asyncio module')
879881
class CFutureInheritanceTests(BaseFutureInheritanceTests,
880882
test_utils.TestCase):
881883
def _get_future_cls(self):

Lib/test/test_asyncio/test_sslproto.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ async def client(addr):
278278

279279
# No garbage is left if SSL is closed uncleanly
280280
client_context = weakref.ref(client_context)
281+
support.gc_collect()
281282
self.assertIsNone(client_context())
282283

283284
def test_create_connection_memory_leak(self):
@@ -341,6 +342,7 @@ async def client(addr):
341342
# No garbage is left for SSL client from loop.create_connection, even
342343
# if user stores the SSLTransport in corresponding protocol instance
343344
client_context = weakref.ref(client_context)
345+
support.gc_collect()
344346
self.assertIsNone(client_context())
345347

346348
def test_start_tls_client_buf_proto_1(self):
@@ -640,6 +642,7 @@ async def client(addr):
640642
# The 10s handshake timeout should be cancelled to free related
641643
# objects without really waiting for 10s
642644
client_sslctx = weakref.ref(client_sslctx)
645+
support.gc_collect()
643646
self.assertIsNone(client_sslctx())
644647

645648
def test_create_connection_ssl_slow_handshake(self):

Lib/test/test_asyncio/test_tasks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,15 +3196,18 @@ class GenericTaskTests(test_utils.TestCase):
31963196
def test_future_subclass(self):
31973197
self.assertTrue(issubclass(asyncio.Task, asyncio.Future))
31983198

3199+
@support.cpython_only
31993200
def test_asyncio_module_compiled(self):
32003201
# Because of circular imports it's easy to make _asyncio
32013202
# module non-importable. This is a simple test that will
32023203
# fail on systems where C modules were successfully compiled
3203-
# (hence the test for _functools), but _asyncio somehow didn't.
3204+
# (hence the test for _functools etc), but _asyncio somehow didn't.
32043205
try:
32053206
import _functools
3207+
import _json
3208+
import _pickle
32063209
except ImportError:
3207-
pass
3210+
self.skipTest('C modules are not available')
32083211
else:
32093212
try:
32103213
import _asyncio
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Made tests relying on the :mod:`_asyncio` C extension module optional to
2+
allow running on alternative Python implementations. Patch by Serhiy
3+
Storchaka.

0 commit comments

Comments
 (0)