Message392771
The PR made sslproto a hard dependency that even import asyncio fails on non-ssl builds and thus anything that indirectly import asyncio also fails. It seems some of the test modules can be skipped. Some parts of the asyncio codebase already has checks for ssl and has to be done for new parts. Attached is a patch to add more checks but it will be helpful to ensure only relevant parts that absolutely require ssl are skipped.
The test_make_socket_transport is slightly tricky since it tries to simulate ssl being not present by patching it but mock does import of sslproto which will fail since SSLAgainErrors is initialized at module level. Perhaps the test can be modified better to only mock if ssl is not present.
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index e54ee309e4..6ccac76dfb 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -41,13 +41,14 @@
from . import exceptions
from . import futures
from . import protocols
-from . import sslproto
from . import staggered
from . import tasks
from . import transports
from . import trsock
from .log import logger
+if ssl is not None:
+ from . import sslproto
__all__ = 'BaseEventLoop',
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index 10852afe2b..ac0dc1978c 100644
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -19,11 +19,17 @@
from . import futures
from . import exceptions
from . import protocols
-from . import sslproto
from . import transports
from . import trsock
from .log import logger
+try:
+ import ssl
+except ImportError: # pragma: no cover
+ ssl = None
+
+if ssl is not None:
+ from . import sslproto
def _set_socket_extra(transport, sock):
transport._extra['socket'] = trsock.TransportSocket(sock)
@@ -826,6 +832,9 @@ def loop(f=None):
server, addr, conn)
protocol = protocol_factory()
if sslcontext is not None:
+ if ssl is None:
+ raise RuntimeError('Python ssl module is not available')
+
self._make_ssl_transport(
conn, protocol, sslcontext, server_side=True,
extra={'peername': addr}, server=server,
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 63ab15f30f..9bc9a03699 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -23,11 +23,12 @@
from . import events
from . import futures
from . import protocols
-from . import sslproto
from . import transports
from . import trsock
from .log import logger
+if ssl is not None:
+ from . import sslproto
def _test_selector_event(selector, fd, event):
# Test if the selector is monitoring 'event' events
@@ -213,6 +214,9 @@ def _accept_connection(
protocol = protocol_factory()
waiter = self.create_future()
if sslcontext:
+ if ssl is None:
+ raise RuntimeError('Python ssl module is not available')
+
transport = self._make_ssl_transport(
conn, protocol, sslcontext, waiter=waiter,
server_side=True, extra=extra, server=server,
diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py
index 349e4f2dca..6aaa7a86be 100644
--- a/Lib/test/test_asyncio/test_selector_events.py
+++ b/Lib/test/test_asyncio/test_selector_events.py
@@ -70,6 +70,7 @@ def test_make_socket_transport(self):
close_transport(transport)
+ @unittest.skipIf(ssl is None, 'No ssl module')
@mock.patch('asyncio.selector_events.ssl', None)
@mock.patch('asyncio.sslproto.ssl', None)
def test_make_ssl_transport_without_ssl_error(self):
diff --git a/Lib/test/test_asyncio/test_ssl.py b/Lib/test/test_asyncio/test_ssl.py
index 38235c63e0..c58346bcab 100644
--- a/Lib/test/test_asyncio/test_ssl.py
+++ b/Lib/test/test_asyncio/test_ssl.py
@@ -1,3 +1,8 @@
+from test.support import import_helper
+
+# Skip tests if we don't have ssl
+import_helper.import_module('ssl')
+
import asyncio
import asyncio.sslproto
import contextlib
diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py
index 79a81bd8c3..2edbb11b58 100644
--- a/Lib/test/test_asyncio/test_sslproto.py
+++ b/Lib/test/test_asyncio/test_sslproto.py
@@ -11,6 +11,9 @@
except ImportError:
ssl = None
+# Skip tests if we don't have ssl
+support.import_helper.import_module('ssl')
+
import asyncio
from asyncio import log
from asyncio import protocols |
|
Date |
User |
Action |
Args |
2021-05-03 07:16:17 | xtreak | set | recipients:
+ xtreak, christian.heimes, asvetlov, yselivanov, pablogsal |
2021-05-03 07:16:17 | xtreak | set | messageid: <1620026177.36.0.95497115815.issue44011@roundup.psfhosted.org> |
2021-05-03 07:16:17 | xtreak | link | issue44011 messages |
2021-05-03 07:16:16 | xtreak | create | |
|