summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2020-06-25 14:11:13 +0200
committerGitHub <noreply@github.com>2020-06-25 08:11:13 -0400
commitd3798ed9f1762dcf632369505d517f476eccde13 (patch)
tree90b3e8b415f39b7c861f39a7818e314dc6774aaa
parentUpdate macOS installer reader for 3.7.8 (diff)
downloadcpython-d3798ed9f1762dcf632369505d517f476eccde13.tar.gz
cpython-d3798ed9f1762dcf632369505d517f476eccde13.tar.bz2
cpython-d3798ed9f1762dcf632369505d517f476eccde13.zip
[3.7] bpo-41009: fix requires_OS_version() class decorator (GH-20942) (GH-20949)
Signed-off-by: Christian Heimes <christian@python.org> Automerge-Triggered-By: @tiran. (cherry picked from commit bb6ec14479f18c32e71e43f2785f177aa17aabbd) Co-authored-by: Christian Heimes <christian@python.org>
-rw-r--r--Lib/test/support/__init__.py38
-rw-r--r--Misc/NEWS.d/next/Tests/2020-06-17-17-27-07.bpo-41009.Rvn6OQ.rst2
2 files changed, 21 insertions, 19 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index b198c2ca763..b78451b9e6c 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -560,25 +560,25 @@ def _requires_unix_version(sysname, min_version):
For example, @_requires_unix_version('FreeBSD', (7, 2)) raises SkipTest if
the FreeBSD version is less than 7.2.
"""
- def decorator(func):
- @functools.wraps(func)
- def wrapper(*args, **kw):
- if platform.system() == sysname:
- version_txt = platform.release().split('-', 1)[0]
- try:
- version = tuple(map(int, version_txt.split('.')))
- except ValueError:
- pass
- else:
- if version < min_version:
- min_version_txt = '.'.join(map(str, min_version))
- raise unittest.SkipTest(
- "%s version %s or higher required, not %s"
- % (sysname, min_version_txt, version_txt))
- return func(*args, **kw)
- wrapper.min_version = min_version
- return wrapper
- return decorator
+ import platform
+ min_version_txt = '.'.join(map(str, min_version))
+ version_txt = platform.release().split('-', 1)[0]
+ if platform.system() == sysname:
+ try:
+ version = tuple(map(int, version_txt.split('.')))
+ except ValueError:
+ skip = False
+ else:
+ skip = version < min_version
+ else:
+ skip = False
+
+ return unittest.skipIf(
+ skip,
+ f"{sysname} version {min_version_txt} or higher required, not "
+ f"{version_txt}"
+ )
+
def requires_freebsd_version(*min_version):
"""Decorator raising SkipTest if the OS is FreeBSD and the FreeBSD version is
diff --git a/Misc/NEWS.d/next/Tests/2020-06-17-17-27-07.bpo-41009.Rvn6OQ.rst b/Misc/NEWS.d/next/Tests/2020-06-17-17-27-07.bpo-41009.Rvn6OQ.rst
new file mode 100644
index 00000000000..1208c119a35
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2020-06-17-17-27-07.bpo-41009.Rvn6OQ.rst
@@ -0,0 +1,2 @@
+Fix use of ``support.require_{linux|mac|freebsd}_version()`` decorators as
+class decorator.