]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41009: fix requires_OS_version() class decorator (GH-20942)
authorChristian Heimes <christian@python.org>
Wed, 17 Jun 2020 17:09:10 +0000 (19:09 +0200)
committerGitHub <noreply@github.com>
Wed, 17 Jun 2020 17:09:10 +0000 (10:09 -0700)
Signed-off-by: Christian Heimes <christian@python.org>
Automerge-Triggered-By: @tiran
Lib/test/support/__init__.py
Misc/NEWS.d/next/Tests/2020-06-17-17-27-07.bpo-41009.Rvn6OQ.rst [new file with mode: 0644]

index 498da6415080f9e1a19033a97fc845ae4b7a6386..da63d9281b107098d396f84de955cf1d84178c7b 100644 (file)
@@ -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
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 (file)
index 0000000..1208c11
--- /dev/null
@@ -0,0 +1,2 @@
+Fix use of ``support.require_{linux|mac|freebsd}_version()`` decorators as
+class decorator.