Skip to content

Commit e272195

Browse files
authored
gh-118362: Skip tests when threading isn't available (#118666)
* Skip tests when threads aren't available * Use ThreadPoolExecutor
1 parent 636b8d9 commit e272195

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

Lib/test/test_free_threading/test_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
from threading import Thread
44
from unittest import TestCase
55

6-
from test.support import is_wasi
6+
from test.support import threading_helper
77

88

99
class C:
1010
def __init__(self, v):
1111
self.v = v
1212

1313

14-
@unittest.skipIf(is_wasi, "WASI has no threads.")
14+
@threading_helper.requires_working_threading()
1515
class TestList(TestCase):
1616
def test_racing_iter_append(self):
1717

Lib/test/test_free_threading/test_monitoring.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import weakref
88

99
from sys import monitoring
10-
from test.support import is_wasi
10+
from test.support import threading_helper
1111
from threading import Thread, _PyRLock
1212
from unittest import TestCase
1313

@@ -87,7 +87,7 @@ def tearDown(self):
8787
monitoring.free_tool_id(self.tool_id)
8888

8989

90-
@unittest.skipIf(is_wasi, "WASI has no threads.")
90+
@threading_helper.requires_working_threading()
9191
class SetPreTraceMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
9292
"""Sets tracing one time after the threads have started"""
9393

@@ -106,7 +106,7 @@ def after_threads(self):
106106
sys.settrace(self.trace_func)
107107

108108

109-
@unittest.skipIf(is_wasi, "WASI has no threads.")
109+
@threading_helper.requires_working_threading()
110110
class MonitoringMultiThreaded(
111111
MonitoringTestMixin, InstrumentationMultiThreadedMixin, TestCase
112112
):
@@ -140,7 +140,7 @@ def during_threads(self):
140140
self.set = not self.set
141141

142142

143-
@unittest.skipIf(is_wasi, "WASI has no threads.")
143+
@threading_helper.requires_working_threading()
144144
class SetTraceMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
145145
"""Uses sys.settrace and repeatedly toggles instrumentation on and off"""
146146

@@ -166,7 +166,7 @@ def during_threads(self):
166166
self.set = not self.set
167167

168168

169-
@unittest.skipIf(is_wasi, "WASI has no threads.")
169+
@threading_helper.requires_working_threading()
170170
class SetProfileMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
171171
"""Uses sys.setprofile and repeatedly toggles instrumentation on and off"""
172172

@@ -192,7 +192,7 @@ def during_threads(self):
192192
self.set = not self.set
193193

194194

195-
@unittest.skipIf(is_wasi, "WASI has no threads.")
195+
@threading_helper.requires_working_threading()
196196
class MonitoringMisc(MonitoringTestMixin, TestCase):
197197
def register_callback(self):
198198
def callback(*args):

Lib/test/test_free_threading/test_type.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import unittest
22

3+
from concurrent.futures import ThreadPoolExecutor
34
from threading import Thread
4-
from multiprocessing.dummy import Pool
55
from unittest import TestCase
66

7-
from test.support import is_wasi
7+
from test.support import threading_helper, import_helper
8+
89

910

1011
NTHREADS = 6
@@ -15,7 +16,7 @@
1516
class A:
1617
attr = 1
1718

18-
@unittest.skipIf(is_wasi, "WASI has no threads.")
19+
@threading_helper.requires_working_threading()
1920
class TestType(TestCase):
2021
def test_attr_cache(self):
2122
def read(id0):
@@ -34,11 +35,10 @@ def write(id0):
3435
A.attr = x
3536

3637

37-
with Pool(NTHREADS) as pool:
38-
pool.apply_async(read, (1,))
39-
pool.apply_async(write, (1,))
40-
pool.close()
41-
pool.join()
38+
with ThreadPoolExecutor(NTHREADS) as pool:
39+
pool.submit(read, (1,))
40+
pool.submit(write, (1,))
41+
pool.shutdown(wait=True)
4242

4343
def test_attr_cache_consistency(self):
4444
class C:

0 commit comments

Comments
 (0)