Skip to content

Commit

Permalink
Use six.wraps in test decorators to allow pytest fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin authored and sethmlarson committed Nov 4, 2019
1 parent 1356f0d commit 5f3b774
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import warnings
import sys
import errno
import functools
import logging
import socket
import ssl
Expand Down Expand Up @@ -56,7 +55,7 @@ def setUp():
def onlyPy279OrNewer(test):
"""Skips this test unless you are on Python 2.7.9 or later."""

@functools.wraps(test)
@six.wraps(test)
def wrapper(*args, **kwargs):
msg = "{name} requires Python 2.7.9+ to run".format(name=test.__name__)
if sys.version_info < (2, 7, 9):
Expand All @@ -69,7 +68,7 @@ def wrapper(*args, **kwargs):
def onlyPy2(test):
"""Skips this test unless you are on Python 2.x"""

@functools.wraps(test)
@six.wraps(test)
def wrapper(*args, **kwargs):
msg = "{name} requires Python 2.x to run".format(name=test.__name__)
if not six.PY2:
Expand All @@ -82,7 +81,7 @@ def wrapper(*args, **kwargs):
def onlyPy3(test):
"""Skips this test unless you are on Python3.x"""

@functools.wraps(test)
@six.wraps(test)
def wrapper(*args, **kwargs):
msg = "{name} requires Python3.x to run".format(name=test.__name__)
if six.PY2:
Expand All @@ -105,7 +104,7 @@ def notBrotlipy():
def notSecureTransport(test):
"""Skips this test when SecureTransport is in use."""

@functools.wraps(test)
@six.wraps(test)
def wrapper(*args, **kwargs):
msg = "{name} does not run with SecureTransport".format(name=test.__name__)
if ssl_.IS_SECURETRANSPORT:
Expand All @@ -118,7 +117,7 @@ def wrapper(*args, **kwargs):
def notOpenSSL098(test):
"""Skips this test for Python 3.4 and 3.5 macOS python.org distributions"""

@functools.wraps(test)
@six.wraps(test)
def wrapper(*args, **kwargs):
is_stdlib_ssl = not ssl_.IS_SECURETRANSPORT and not ssl_.IS_PYOPENSSL
if is_stdlib_ssl and ssl.OPENSSL_VERSION == "OpenSSL 0.9.8zh 14 Jan 2016":
Expand Down Expand Up @@ -153,7 +152,7 @@ def _has_route():
else:
raise

@functools.wraps(test)
@six.wraps(test)
def wrapper(*args, **kwargs):
global _requires_network_has_route

Expand All @@ -172,7 +171,7 @@ def wrapper(*args, **kwargs):


def requires_ssl_context_keyfile_password(test):
@functools.wraps(test)
@six.wraps(test)
def wrapper(*args, **kwargs):
if (
not ssl_.IS_PYOPENSSL and sys.version_info < (2, 7, 9)
Expand All @@ -194,7 +193,7 @@ def fails_on_travis_gce(test):
https://github.com/urllib3/urllib3/pull/1475#issuecomment-440788064
"""

@functools.wraps(test)
@six.wraps(test)
def wrapper(*args, **kwargs):
if os.environ.get("TRAVIS_INFRA") in ("gce", "unknown"):
pytest.xfail("%s is expected to fail on Travis GCE builds" % test.__name__)
Expand Down

0 comments on commit 5f3b774

Please sign in to comment.