Use decorators to mark tests as xfail in PyPy2
This was not possibly until now because of functool.wraps for older
Pythons.
MODIFY
test/__init__.py
test/__init__.py
@@ -5,6 +5,7 @@ import logging
import socket
import ssl
import os
+import platform
import pytest
@@ -91,6 +92,20 @@ def onlyPy3(test):
return wrapper
+def notPyPy2(test):
+ """Skips this test on PyPy2"""
+
+ @six.wraps(test)
+ def wrapper(*args, **kwargs):
+ # https://github.com/testing-cabal/mock/issues/438
+ msg = "{} fails with PyPy 2 dues to funcsigs bugs".format(test.__name__)
+ if platform.python_implementation() == "PyPy" and sys.version_info[0] == 2:
+ pytest.xfail(msg)
+ return test(*args, **kwargs)
+
+ return wrapper
+
+
def onlyBrotlipy():
return pytest.mark.skipif(brotli is None, reason="only run if brotlipy is present")

MODIFY
test/test_ssl.py
test/test_ssl.py
-import platform
-import sys
-
import mock
import pytest
from urllib3.util import ssl_
from urllib3.exceptions import SNIMissingWarning
+from test import notPyPy2
+
@pytest.mark.parametrize(
"addr",
@@ -127,10 +126,8 @@ def test_wrap_socket_given_context_no_load_default_certs():
context.load_default_certs.assert_not_called()
+@notPyPy2
def test_wrap_socket_given_ca_certs_no_load_default_certs(monkeypatch):
- if platform.python_implementation() == "PyPy" and sys.version_info[0] == 2:
- # https://github.com/testing-cabal/mock/issues/438
- pytest.xfail("fails with PyPy for Python 2 dues to funcsigs bug")
context = mock.create_autospec(ssl_.SSLContext)
context.load_default_certs = mock.Mock()
context.options = 0

MODIFY
test/with_dummyserver/test_socketlevel.py
test/with_dummyserver/test_socketlevel.py
# TODO: Break this module up into pieces. Maybe group by functionality tested
# rather than the socket level-ness of it.
-import platform
-import sys
-
from urllib3 import HTTPConnectionPool, HTTPSConnectionPool
from urllib3.poolmanager import proxy_from_url
from urllib3.exceptions import (
@@ -48,6 +45,7 @@ import mock
import pytest
from test import (
+ notPyPy2,
fails_on_travis_gce,
requires_ssl_context_keyfile_password,
SHORT_TIMEOUT,
@@ -1321,11 +1319,8 @@ class TestSSL(SocketDummyServerTestCase):
pool.request("GET", "/", timeout=SHORT_TIMEOUT)
context.load_default_certs.assert_called_with()
+ @notPyPy2
def test_ssl_dont_load_default_certs_when_given(self):
- if platform.python_implementation() == "PyPy" and sys.version_info[0] == 2:
- # https://github.com/testing-cabal/mock/issues/438
- pytest.xfail("fails with PyPy for Python 2 dues to funcsigs bug")
-
def socket_handler(listener):
sock = listener.accept()[0]
ssl_sock = ssl.wrap_socket(

Use decorators to mark tests as xfail in PyPy2

This was not possibly until now because of functool.wraps for older
Pythons.