8000 bpo-45011: Fix test_asyncio without C module _asyncio by serhiy-storchaka · Pull Request #27968 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45011: Fix test_asyncio without C module _asyncio #27968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Lib/test/test_asyncio/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,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):
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_asyncio/test_sslproto.py
F2DB
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2875,15 +2875,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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
0