From a9a455e8d72c6a98b95c17baedb305fdcfa0fe3e Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Mon, 17 Jun 2024 22:29:06 +0200 Subject: [PATCH 1/6] Skip `test_freethreading` with GIL --- Lib/test/test_free_threading/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_free_threading/__init__.py b/Lib/test/test_free_threading/__init__.py index 9a89d27ba9f979..5f13891e7ee8cc 100644 --- a/Lib/test/test_free_threading/__init__.py +++ b/Lib/test/test_free_threading/__init__.py @@ -2,6 +2,6 @@ from test import support - -def load_tests(*args): - return support.load_package_tests(os.path.dirname(__file__), *args) +if support.Py_GIL_DISABLED: + def load_tests(*args): + return support.load_package_tests(os.path.dirname(__file__), *args) From 7146d3cb97c9ce0c747eefaa020e50f414e17903 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Mon, 17 Jun 2024 22:33:57 +0200 Subject: [PATCH 2/6] Reduce diff --- Lib/test/test_free_threading/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_free_threading/__init__.py b/Lib/test/test_free_threading/__init__.py index 5f13891e7ee8cc..154514b6a18668 100644 --- a/Lib/test/test_free_threading/__init__.py +++ b/Lib/test/test_free_threading/__init__.py @@ -2,6 +2,7 @@ from test import support + if support.Py_GIL_DISABLED: def load_tests(*args): return support.load_package_tests(os.path.dirname(__file__), *args) From 89cf80dc0814403f4a86bcb0fdff64ea2474faa6 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Mon, 17 Jun 2024 22:35:06 +0200 Subject: [PATCH 3/6] Don't import `os` when not necessary --- Lib/test/test_free_threading/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_free_threading/__init__.py b/Lib/test/test_free_threading/__init__.py index 154514b6a18668..573d9b92a3bfb5 100644 --- a/Lib/test/test_free_threading/__init__.py +++ b/Lib/test/test_free_threading/__init__.py @@ -1,8 +1,8 @@ -import os - from test import support if support.Py_GIL_DISABLED: + import os + def load_tests(*args): return support.load_package_tests(os.path.dirname(__file__), *args) From 1071cb9d8e29596ddb8289a6cb7edd8901aa9da6 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Tue, 18 Jun 2024 07:05:17 +0200 Subject: [PATCH 4/6] Use `support.skipUnless()` --- Lib/test/test_free_threading/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_free_threading/__init__.py b/Lib/test/test_free_threading/__init__.py index 573d9b92a3bfb5..387d95f597a9ae 100644 --- a/Lib/test/test_free_threading/__init__.py +++ b/Lib/test/test_free_threading/__init__.py @@ -1,8 +1,8 @@ -from test import support +import os +from test import support -if support.Py_GIL_DISABLED: - import os - def load_tests(*args): - return support.load_package_tests(os.path.dirname(__file__), *args) +@support.skipUnless(support.Py_GIL_DISABLED, "GIL enabled") +def load_tests(*args): + return support.load_package_tests(os.path.dirname(__file__), *args) From 41793d41d8af3ec86677c8081d9d99d100b4a848 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Tue, 18 Jun 2024 07:40:56 +0200 Subject: [PATCH 5/6] Use `unittest.skipUnless` --- Lib/test/test_free_threading/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_free_threading/__init__.py b/Lib/test/test_free_threading/__init__.py index 387d95f597a9ae..e5901ce44bee74 100644 --- a/Lib/test/test_free_threading/__init__.py +++ b/Lib/test/test_free_threading/__init__.py @@ -1,8 +1,9 @@ import os from test import support +from unittest import skipUnless -@support.skipUnless(support.Py_GIL_DISABLED, "GIL enabled") +@skipUnless(support.Py_GIL_DISABLED, "GIL enabled") def load_tests(*args): return support.load_package_tests(os.path.dirname(__file__), *args) From 465759aa980c03bd14f24a3f31e9127d0315eaa9 Mon Sep 17 00:00:00 2001 From: Nineteendo Date: Tue, 18 Jun 2024 09:34:46 +0200 Subject: [PATCH 6/6] Raise at module level Co-authored-by: Victor Stinner --- Lib/test/test_free_threading/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_free_threading/__init__.py b/Lib/test/test_free_threading/__init__.py index e5901ce44bee74..34e1ad30e11097 100644 --- a/Lib/test/test_free_threading/__init__.py +++ b/Lib/test/test_free_threading/__init__.py @@ -1,9 +1,11 @@ import os +import unittest from test import support -from unittest import skipUnless -@skipUnless(support.Py_GIL_DISABLED, "GIL enabled") +if not support.Py_GIL_DISABLED: + raise unittest.SkipTest("GIL enabled") + def load_tests(*args): return support.load_package_tests(os.path.dirname(__file__), *args)