From 358d98db0cd3c5c5d2b099b70a5a48d18194077c Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 17 Jun 2020 17:27:39 +0200 Subject: [PATCH 1/2] bpo-41009: fix requires_OS_version() class decorator Signed-off-by: Christian Heimes --- Lib/test/support/__init__.py | 39 +++++++++---------- .../2020-06-17-17-27-07.bpo-41009.Rvn6OQ.rst | 2 + 2 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2020-06-17-17-27-07.bpo-41009.Rvn6OQ.rst diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 498da6415080f9..2ba65ed2046e59 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 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 00000000000000..f4f59a6df656b3 --- /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()`` decorator as +class decorator. From de2d8d84fabdc070fbf68554eb886d0e8f78cbab Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 17 Jun 2020 18:36:07 +0200 Subject: [PATCH 2/2] Address code review Signed-off-by: Christian Heimes --- Lib/test/support/__init__.py | 2 +- Misc/NEWS.d/next/Tests/2020-06-17-17-27-07.bpo-41009.Rvn6OQ.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 2ba65ed2046e59..da63d9281b1070 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -315,7 +315,7 @@ def _requires_unix_version(sysname, min_version): return unittest.skipIf( skip, f"{sysname} version {min_version_txt} or higher required, not " - f"{version_txt}." + f"{version_txt}" ) 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 index f4f59a6df656b3..1208c119a35562 100644 --- 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 @@ -1,2 +1,2 @@ -Fix use of ``support.require_{linux|mac|freebsd}_version()`` decorator as +Fix use of ``support.require_{linux|mac|freebsd}_version()`` decorators as class decorator.