diff options
author | Christian Heimes <christian@python.org> | 2020-06-17 19:09:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-17 10:09:10 -0700 |
commit | bb6ec14479f18c32e71e43f2785f177aa17aabbd (patch) | |
tree | 7a4a77113064832ed797636e3d1cabf588c0f2bf /Lib/test | |
parent | 8362893e3fe083df2ec8bb94c28b1a78383eadbf (diff) | |
download | cpython-git-bb6ec14479f18c32e71e43f2785f177aa17aabbd.tar.gz |
bpo-41009: fix requires_OS_version() class decorator (GH-20942)
Signed-off-by: Christian Heimes <christian@python.org>
Automerge-Triggered-By: @tiran
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/support/__init__.py | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 498da64150..da63d9281b 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -299,26 +299,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): - import platform - 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 |