Skip to content

Commit dcaacd9

Browse files
[3.12] pythongh-108416: Mark slow test methods with @requires_resource('cpu') (pythonGH-108421) (python#108798)
pythongh-108416: Mark slow test methods with @requires_resource('cpu') (pythonGH-108421) Only mark tests which spend significant system or user time, by itself or in subprocesses. (cherry picked from commit f3ba0a7) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 7269916 commit dcaacd9

32 files changed

+57
-5
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ def test_set_executable(self):
329329
p.join()
330330
self.assertEqual(p.exitcode, 0)
331331

332+
@support.requires_resource('cpu')
332333
def test_args_argument(self):
333334
# bpo-45735: Using list or tuple as *args* in constructor could
334335
# achieve the same effect.
@@ -4466,6 +4467,7 @@ def test_finalize(self):
44664467
result = [obj for obj in iter(conn.recv, 'STOP')]
44674468
self.assertEqual(result, ['a', 'b', 'd10', 'd03', 'd02', 'd01', 'e'])
44684469

4470+
@support.requires_resource('cpu')
44694471
def test_thread_safety(self):
44704472
# bpo-24484: _run_finalizers() should be thread-safe
44714473
def cb():

Lib/test/pickletester.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,7 @@ def check_frame_opcodes(self, pickled):
25762576
self.assertLess(pos - frameless_start, self.FRAME_SIZE_MIN)
25772577

25782578
@support.skip_if_pgo_task
2579+
@support.requires_resource('cpu')
25792580
def test_framing_many_objects(self):
25802581
obj = list(range(10**5))
25812582
for proto in range(4, pickle.HIGHEST_PROTOCOL + 1):

Lib/test/test_ast.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,6 +1999,7 @@ def test_nameconstant(self):
19991999
'ast.NameConstant is deprecated and will be removed in Python 3.14; use ast.Constant instead',
20002000
])
20012001

2002+
@support.requires_resource('cpu')
20022003
def test_stdlib_validates(self):
20032004
stdlib = os.path.dirname(ast.__file__)
20042005
tests = [fn for fn in os.listdir(stdlib) if fn.endswith(".py")]

Lib/test/test_buffer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ def match(req, flag):
10281028
ndim=ndim, shape=shape, strides=strides,
10291029
lst=lst, sliced=sliced)
10301030

1031+
@support.requires_resource('cpu')
10311032
def test_ndarray_getbuf(self):
10321033
requests = (
10331034
# distinct flags
@@ -2759,6 +2760,7 @@ def iter_roundtrip(ex, m, items, fmt):
27592760
m = memoryview(ex)
27602761
iter_roundtrip(ex, m, items, fmt)
27612762

2763+
@support.requires_resource('cpu')
27622764
def test_memoryview_cast_1D_ND(self):
27632765
# Cast between C-contiguous buffers. At least one buffer must
27642766
# be 1D, at least one format must be 'c', 'b' or 'B'.

Lib/test/test_builtin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ def test_filter_pickle(self):
927927
f2 = filter(filter_char, "abcdeabcde")
928928
self.check_iter_pickle(f1, list(f2), proto)
929929

930+
@support.requires_resource('cpu')
930931
def test_filter_dealloc(self):
931932
# Tests recursive deallocation of nested filter objects using the
932933
# thrashcan mechanism. See gh-102356 for more details.

Lib/test/test_compile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ def test_path_like_objects(self):
784784
# An implicit test for PyUnicode_FSDecoder().
785785
compile("42", FakePath("test_compile_pathlike"), "single")
786786

787+
@support.requires_resource('cpu')
787788
def test_stack_overflow(self):
788789
# bpo-31113: Stack overflow when compile a long sequence of
789790
# complex statements.

Lib/test/test_compileall.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ def test_no_args_compiles_path(self):
551551
self.assertNotCompiled(self.barfn)
552552

553553
@without_source_date_epoch # timestamp invalidation test
554+
@support.requires_resource('cpu')
554555
def test_no_args_respects_force_flag(self):
555556
bazfn = script_helper.make_script(self.directory, 'baz', '')
556557
with self.temporary_pycache_prefix() as env:
@@ -568,6 +569,7 @@ def test_no_args_respects_force_flag(self):
568569
mtime2 = os.stat(pycpath).st_mtime
569570
self.assertNotEqual(mtime, mtime2)
570571

572+
@support.requires_resource('cpu')
571573
def test_no_args_respects_quiet_flag(self):
572574
script_helper.make_script(self.directory, 'baz', '')
573575
with self.temporary_pycache_prefix() as env:

Lib/test/test_concurrent_futures/test_thread_pool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import threading
77
import unittest
88
from concurrent import futures
9+
from test import support
910

1011
from .executor import ExecutorTest, mul
1112
from .util import BaseTestCase, ThreadPoolMixin, setup_module
@@ -49,6 +50,7 @@ def test_idle_thread_reuse(self):
4950
executor.shutdown(wait=True)
5051

5152
@unittest.skipUnless(hasattr(os, 'register_at_fork'), 'need os.register_at_fork')
53+
@support.requires_resource('cpu')
5254
def test_hang_global_shutdown_lock(self):
5355
# bpo-45021: _global_shutdown_lock should be reinitialized in the child
5456
# process, otherwise it will never exit

Lib/test/test_context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
import unittest
88
import weakref
9+
from test import support
910
from test.support import threading_helper
1011

1112
try:
@@ -570,6 +571,7 @@ def test_hamt_collision_3(self):
570571

571572
self.assertEqual({k.name for k in h.keys()}, {'C', 'D', 'E'})
572573

574+
@support.requires_resource('cpu')
573575
def test_hamt_stress(self):
574576
COLLECTION_SIZE = 7000
575577
TEST_ITERS_EVERY = 647

Lib/test/test_cppext/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
@support.requires_subprocess()
1919
class TestCPPExt(unittest.TestCase):
20+
@support.requires_resource('cpu')
2021
def test_build_cpp11(self):
2122
self.check_build(False, '_testcpp11ext')
2223

24+
@support.requires_resource('cpu')
2325
def test_build_cpp03(self):
2426
self.check_build(True, '_testcpp03ext')
2527

0 commit comments

Comments
 (0)