8000 [3.7] bpo-41009: fix requires_OS_version() class decorator (GH-20942)… · python/cpython@d3798ed · GitHub
[go: up one dir, main page]

Skip to content

Commit d3798ed

Browse files
authored
[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 bb6ec14) Co-authored-by: Christian Heimes <christian@python.org>
1 parent 934c1fa commit d3798ed

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

Lib/test/support/__init__.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -560,25 +560,25 @@ def _requires_unix_version(sysname, min_version):
560560
For example, @_requires_unix_version('FreeBSD', (7, 2)) raises SkipTest if
561561
the FreeBSD version is less than 7.2.
562562
"""
563-
def decorator(func):
564-
@functools.wraps(func)
565-
def wrapper(*args, **kw):
566-
if platform.system() == sysname:
567-
version_txt = platform.release().split('-', 1)[0]
568-
try:
569-
version = tuple(map(int, version_txt.split('.')))
570-
except ValueError:
571-
pass
572-
else:
573-
if version < min_version:
574-
min_version_txt = '.'.join(map(str, min_version))
575-
raise unittest.SkipTest(
576-
"%s version %s or higher required, not %s"
577-
% (sysname, min_version_txt, version_txt))
578-
return func(*args, **kw)
579-
wrapper.min_version = min_version
580-
return wrapper
581-
return decorator
563+
import platform
564+
min_version_txt = '.'.join(map(str, min_version))
565+
version_txt = platform.release().split('-', 1)[0]
566+
if platform.system() == sysname:
567+
try:
568+
version = tuple(map(int, version_txt.split('.')))
569+
except ValueError:
570+
skip = False
571+
else:
572+
skip = version < min_version
573+
else:
574+
skip = False
575+
576+
return unittest.skipIf(
577+
skip,
578+
f"{sysname} version {min_version_txt} or higher required, not "
579+
f"{version_txt}"
580+
)
581+
582582

583583
def requires_freebsd_version(*min_version):
584584
"""Decorator raising SkipTest if the OS is FreeBSD and the FreeBSD version is
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix use of ``support.require_{linux|mac|freebsd}_version()`` decorators as
2+
class decorator.

0 commit comments

Comments
 (0)
0