]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118362: Skip tests when threading isn't available (#118666)
authorDino Viehland <dinoviehland@meta.com>
Mon, 6 May 2024 23:45:04 +0000 (16:45 -0700)
committerGitHub <noreply@github.com>
Mon, 6 May 2024 23:45:04 +0000 (16:45 -0700)
* Skip tests when threads aren't available

* Use ThreadPoolExecutor

Lib/test/test_free_threading/test_list.py
Lib/test/test_free_threading/test_monitoring.py
Lib/test/test_free_threading/test_type.py

index 79cb0a93092365771096fe19404d4de9fe94ba59..6ad806d67a80eddd2ec6b648a5655b28c10bc6d5 100644 (file)
@@ -3,7 +3,7 @@ import unittest
 from threading import Thread
 from unittest import TestCase
 
-from test.support import is_wasi
+from test.support import threading_helper
 
 
 class C:
@@ -11,7 +11,7 @@ class C:
         self.v = v
 
 
-@unittest.skipIf(is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class TestList(TestCase):
     def test_racing_iter_append(self):
 
index fa588046bf9923da13e5ced29b9c87291422ff62..3a3f1ba3b605d675b04f712dd1c2a7b233585232 100644 (file)
@@ -7,7 +7,7 @@ import unittest
 import weakref
 
 from sys import monitoring
-from test.support import is_wasi
+from test.support import threading_helper
 from threading import Thread, _PyRLock
 from unittest import TestCase
 
@@ -87,7 +87,7 @@ class MonitoringTestMixin:
         monitoring.free_tool_id(self.tool_id)
 
 
-@unittest.skipIf(is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class SetPreTraceMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
     """Sets tracing one time after the threads have started"""
 
@@ -106,7 +106,7 @@ class SetPreTraceMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
         sys.settrace(self.trace_func)
 
 
-@unittest.skipIf(is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class MonitoringMultiThreaded(
     MonitoringTestMixin, InstrumentationMultiThreadedMixin, TestCase
 ):
@@ -140,7 +140,7 @@ class MonitoringMultiThreaded(
         self.set = not self.set
 
 
-@unittest.skipIf(is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class SetTraceMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
     """Uses sys.settrace and repeatedly toggles instrumentation on and off"""
 
@@ -166,7 +166,7 @@ class SetTraceMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
         self.set = not self.set
 
 
-@unittest.skipIf(is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class SetProfileMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
     """Uses sys.setprofile and repeatedly toggles instrumentation on and off"""
 
@@ -192,7 +192,7 @@ class SetProfileMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
         self.set = not self.set
 
 
-@unittest.skipIf(is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class MonitoringMisc(MonitoringTestMixin, TestCase):
     def register_callback(self):
         def callback(*args):
index 76208c42fc8aeae84d493faf9b3d09888345d020..6eead198deed46283c32acdf4cb914e2166de256 100644 (file)
@@ -1,10 +1,11 @@
 import unittest
 
+from concurrent.futures import ThreadPoolExecutor
 from threading import Thread
-from multiprocessing.dummy import Pool
 from unittest import TestCase
 
-from test.support import is_wasi
+from test.support import threading_helper, import_helper
+
 
 
 NTHREADS = 6
@@ -15,7 +16,7 @@ ITERS = 100
 class A:
     attr = 1
 
-@unittest.skipIf(is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class TestType(TestCase):
     def test_attr_cache(self):
         def read(id0):
@@ -34,11 +35,10 @@ class TestType(TestCase):
                     A.attr = x
 
 
-        with Pool(NTHREADS) as pool:
-            pool.apply_async(read, (1,))
-            pool.apply_async(write, (1,))
-            pool.close()
-            pool.join()
+        with ThreadPoolExecutor(NTHREADS) as pool:
+            pool.submit(read, (1,))
+            pool.submit(write, (1,))
+            pool.shutdown(wait=True)
 
     def test_attr_cache_consistency(self):
         class C: