Skip to content

Commit 7984a73

Browse files
committed
tests: pypy2 does not support ssl.TLSVersion
1 parent 9bee0d9 commit 7984a73

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

tests/test_https.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import platform
12
import socket
23
import ssl
4+
import sys
35

46
import pytest
57
from six.moves import urllib
@@ -73,17 +75,25 @@ def test_not_trusted_ca():
7375
pass
7476

7577

76-
ssl_context_accept_version = hasattr(tests.ssl_context(), "maximum_version") and hasattr(
77-
tests.ssl_context(), "minimum_version"
78+
ssl_context_accept_version = (
79+
hasattr(tests.ssl_context(), "maximum_version")
80+
and hasattr(tests.ssl_context(), "minimum_version")
81+
and not (platform.python_implementation().lower() == "pypy" and sys.version_info < (3,))
82+
)
83+
tls_minmax_versions = (
84+
(None, "TLSv1_2", ssl.TLSVersion.TLSv1_2)
85+
# TODO remove pypy2 workaround `and hasattr` clause
86+
if ssl_context_accept_version and hasattr(ssl, "TLSVersion") else (None,)
7887
)
7988

8089

8190
@pytest.mark.skipif(not ssl_context_accept_version, reason="ssl doesn't support TLS min/max")
8291
@pytest.mark.parametrize("attr", ("maximum_version", "minimum_version"))
83-
@pytest.mark.parametrize("version", (None, "TLSv1_2", ssl.TLSVersion.TLSv1_2) if ssl_context_accept_version else (None,))
92+
@pytest.mark.parametrize("version", tls_minmax_versions)
8493
def test_set_tls_version(attr, version):
94+
ctx = tests.ssl_context()
8595
# We expect failure on Python < 3.7 or OpenSSL < 1.1
86-
expect_success = hasattr(ssl.SSLContext(), attr)
96+
expect_success = hasattr(ctx, attr)
8797
kwargs = {"tls_" + attr: version}
8898
http = httplib2.Http(**kwargs)
8999
try:
@@ -94,10 +104,7 @@ def test_set_tls_version(attr, version):
94104
assert expect_success
95105

96106

97-
@pytest.mark.skipif(
98-
not hasattr(tests.ssl_context(), "maximum_version"),
99-
reason="ssl doesn't support TLS min/max",
100-
)
107+
@pytest.mark.skipif(not ssl_context_accept_version, reason="ssl doesn't support TLS min/max")
101108
def test_max_tls_version():
102109
http = httplib2.Http(ca_certs=tests.CA_CERTS, tls_maximum_version="TLSv1_2")
103110
with tests.server_const_http(tls=True) as uri:

0 commit comments

Comments
 (0)