8000 bpo-45011: Fix test_asyncio without C module _asyncio (GH-27968) · python/cpython@9f814be · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 9f814be

Browse files
bpo-45011: Fix test_asyncio without C module _asyncio (GH-27968)
Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit 7dc505b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 32c1caa commit 9f814be

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

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
@@ -918,6 +918,8 @@ def _get_future_cls(self):
918918
return futures._PyFuture
919919

920920

921+
@unittest.skipUnless(hasattr(futures, '_CFuture'),
922+
'requires the C _asyncio module')
921923
class CFutureInheritanceTests(BaseFutureInheritanceTests,
922924
test_utils.TestCase):
923925
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
@@ -3275,15 +3275,18 @@ class GenericTaskTests(test_utils.TestCase):
32753275
def test_future_subclass(self):
32763276
self.assertTrue(issubclass(asyncio.Task, asyncio.Future))
32773277

3278+
@support.cpython_only
32783279
def test_asyncio_module_compiled(self):
32793280
# Because of circular imports it's easy to make _asyncio
32803281
# module non-importable. This is a simple test that will
32813282
# fail on systems where C modules were successfully compiled
3282-
# (hence the test for _functools), but _asyncio somehow didn't.
3283+
# (hence the test for _functools etc), but _asyncio somehow didn't.
32833284
try:
32843285
import _functools
3286+
import _json
3287+
import _pickle
32853288
except ImportError:
3286-
pass
3289+
self.skipTest('C modules are not available')
32873290
else:
32883291
try:
32893292
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)
0