Skip to content

Commit f3ba0a7

Browse files
gh-108416: Mark slow test methods with @requires_resource('cpu') (GH-108421)
Only mark tests which spend significant system or user time, by itself or in subprocesses.
1 parent aa52888 commit f3ba0a7

32 files changed

+57
-8
lines changed

Lib/test/_test_multiprocessing.py

+2
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.
@@ -4504,6 +4505,7 @@ def test_finalize(self):
45044505
result = [obj for obj in iter(conn.recv, 'STOP')]
45054506
self.assertEqual(result, ['a', 'b', 'd10', 'd03', 'd02', 'd01', 'e'])
45064507

4508+
@support.requires_resource('cpu')
45074509
def test_thread_safety(self):
45084510
# bpo-24484: _run_finalizers() should be thread-safe
45094511
def cb():

Lib/test/pickletester.py

+1
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

+1
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,7 @@ def test_nameconstant(self):
20312031
'ast.NameConstant is deprecated and will be removed in Python 3.14; use ast.Constant instead',
20322032
])
20332033

2034+
@support.requires_resource('cpu')
20342035
def test_stdlib_validates(self):
20352036
stdlib = os.path.dirname(ast.__file__)
20362037
tests = [fn for fn in os.listdir(stdlib) if fn.endswith(".py")]

Lib/test/test_buffer.py

+2
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,7 @@ def match(req, flag):
10291029
ndim=ndim, shape=shape, strides=strides,
10301030
lst=lst, sliced=sliced)
10311031

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

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

Lib/test/test_builtin.py

+1
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ def test_filter_pickle(self):
952952
f2 = filter(filter_char, "abcdeabcde")
953953
self.check_iter_pickle(f1, list(f2), proto)
954954

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

Lib/test/test_compile.py

+1
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

+2
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

+2
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

+2
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

+2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

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

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

Lib/test/test_descr.py

+1
Original file line numberDiff line numberDiff line change
@@ -4457,6 +4457,7 @@ class Oops(object):
44574457
o.whatever = Provoker(o)
44584458
del o
44594459

4460+
@support.requires_resource('cpu')
44604461
def test_wrapper_segfault(self):
44614462
# SF 927248: deeply nested wrappers could cause stack overflow
44624463
f = lambda:None

Lib/test/test_email/test_email.py

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from email import quoprimime
3939
from email import utils
4040

41+
from test import support
4142
from test.support import threading_helper
4243
from test.support.os_helper import unlink
4344
from test.test_email import openfile, TestEmailBase
@@ -3358,6 +3359,7 @@ def test_getaddresses_header_obj(self):
33583359
self.assertEqual(addrs[0][1], 'aperson@dom.ain')
33593360

33603361
@threading_helper.requires_working_threading()
3362+
@support.requires_resource('cpu')
33613363
def test_make_msgid_collisions(self):
33623364
# Test make_msgid uniqueness, even with multiple threads
33633365
class MsgidsThread(Thread):

Lib/test/test_exceptions.py

+1
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,7 @@ def g():
13501350

13511351

13521352
@cpython_only
1353+
@support.requires_resource('cpu')
13531354
def test_trashcan_recursion(self):
13541355
# See bpo-33930
13551356

Lib/test/test_gdb.py

+7
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def assertGdbRepr(self, val, exp_repr=None):
317317
('%r did not equal expected %r; full output was:\n%s'
318318
% (gdb_repr, exp_repr, gdb_output)))
319319

320+
@support.requires_resource('cpu')
320321
def test_int(self):
321322
'Verify the pretty-printing of various int values'
322323
self.assertGdbRepr(42)
@@ -343,6 +344,7 @@ def test_lists(self):
343344
self.assertGdbRepr([])
344345
self.assertGdbRepr(list(range(5)))
345346

347+
@support.requires_resource('cpu')
346348
def test_bytes(self):
347349
'Verify the pretty-printing of bytes'
348350
self.assertGdbRepr(b'')
@@ -357,6 +359,7 @@ def test_bytes(self):
357359

358360
self.assertGdbRepr(bytes([b for b in range(255)]))
359361

362+
@support.requires_resource('cpu')
360363
def test_strings(self):
361364
'Verify the pretty-printing of unicode strings'
362365
# We cannot simply call locale.getpreferredencoding() here,
@@ -407,6 +410,7 @@ def test_tuples(self):
407410
self.assertGdbRepr((1,), '(1,)')
408411
self.assertGdbRepr(('foo', 'bar', 'baz'))
409412

413+
@support.requires_resource('cpu')
410414
def test_sets(self):
411415
'Verify the pretty-printing of sets'
412416
if (gdb_major_version, gdb_minor_version) < (7, 3):
@@ -425,6 +429,7 @@ def test_sets(self):
425429
id(s)''')
426430
self.assertEqual(gdb_repr, "{'b'}")
427431

432+
@support.requires_resource('cpu')
428433
def test_frozensets(self):
429434
'Verify the pretty-printing of frozensets'
430435
if (gdb_major_version, gdb_minor_version) < (7, 3):
@@ -828,6 +833,7 @@ def test_bt_full(self):
828833

829834
@unittest.skipIf(python_is_optimized(),
830835
"Python was compiled with optimizations")
836+
@support.requires_resource('cpu')
831837
def test_threads(self):
832838
'Verify that "py-bt" indicates threads that are waiting for the GIL'
833839
cmd = '''
@@ -889,6 +895,7 @@ def test_gc(self):
889895

890896
@unittest.skipIf(python_is_optimized(),
891897
"Python was compiled with optimizations")
898+
@support.requires_resource('cpu')
892899
# Some older versions of gdb will fail with
893900
# "Cannot find new threads: generic error"
894901
# unless we add LD_PRELOAD=PATH-TO-libpthread.so.1 as a workaround

Lib/test/test_interpreters.py

+2
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,14 @@ class StressTests(TestBase):
469469
# In these tests we generally want a lot of interpreters,
470470
# but not so many that any test takes too long.
471471

472+
@support.requires_resource('cpu')
472473
def test_create_many_sequential(self):
473474
alive = []
474475
for _ in range(100):
475476
interp = interpreters.create()
476477
alive.append(interp)
477478

479+
@support.requires_resource('cpu')
478480
def test_create_many_threaded(self):
479481
alive = []
480482
def task():

Lib/test/test_itertools.py

+1
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,7 @@ def gen2(x):
24012401
self.assertEqual(hist, [0,1])
24022402

24032403
@support.skip_if_pgo_task
2404+
@support.requires_resource('cpu')
24042405
def test_long_chain_of_empty_iterables(self):
24052406
# Make sure itertools.chain doesn't run into recursion limits when
24062407
# dealing with long chains of empty iterables. Even with a high

Lib/test/test_largefile.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import socket
99
import shutil
1010
import threading
11-
from test.support import requires, bigmemtest
11+
from test.support import requires, bigmemtest, requires_resource
1212
from test.support import SHORT_TIMEOUT
1313
from test.support import socket_helper
1414
from test.support.os_helper import TESTFN, unlink
@@ -173,6 +173,7 @@ class TestCopyfile(LargeFileTest, unittest.TestCase):
173173
# Exact required disk space would be (size * 2), but let's give it a
174174
# bit more tolerance.
175175
@skip_no_disk_space(TESTFN, size * 2.5)
176+
@requires_resource('cpu')
176177
def test_it(self):
177178
# Internally shutil.copyfile() can use "fast copy" methods like
178179
# os.sendfile().
@@ -222,6 +223,7 @@ def run(sock):
222223
# Exact required disk space would be (size * 2), but let's give it a
223224
# bit more tolerance.
224225
@skip_no_disk_space(TESTFN, size * 2.5)
226+
@requires_resource('cpu')
225227
def test_it(self):
226228
port = socket_helper.find_unused_port()
227229
with socket.create_server(("", port)) as sock:

Lib/test/test_multibytecodec.py

+1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ def test_iso2022_jp_g0(self):
363363
e = '\u3406'.encode(encoding)
364364
self.assertFalse(any(x > 0x80 for x in e))
365365

366+
@support.requires_resource('cpu')
366367
def test_bug1572832(self):
367368
for x in range(0x10000, 0x110000):
368369
# Any ISO 2022 codec will cause the segfault

Lib/test/test_peepholer.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import textwrap
55
import unittest
66

7+
from test import support
78
from test.support.bytecode_helper import BytecodeTestCase, CfgOptimizationTestCase
89

910

@@ -522,6 +523,7 @@ def genexpr():
522523
return (y for x in a for y in [f(x)])
523524
self.assertEqual(count_instr_recursively(genexpr, 'FOR_ITER'), 1)
524525

526+
@support.requires_resource('cpu')
525527
def test_format_combinations(self):
526528
flags = '-+ #0'
527529
testcases = [

Lib/test/test_runpy.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import textwrap
1313
import unittest
1414
import warnings
15-
from test.support import no_tracing, verbose, requires_subprocess
15+
from test.support import no_tracing, verbose, requires_subprocess, requires_resource
1616
from test.support.import_helper import forget, make_legacy_pyc, unload
1717
from test.support.os_helper import create_empty_file, temp_dir
1818
from test.support.script_helper import make_script, make_zip_script
@@ -733,6 +733,7 @@ def test_zipfile_error(self):
733733
self._check_import_error(zip_name, msg)
734734

735735
@no_tracing
736+
@requires_resource('cpu')
736737
def test_main_recursion_error(self):
737738
with temp_dir() as script_dir, temp_dir() as dummy_dir:
738739
mod_name = '__main__'

Lib/test/test_selectors.py

+1
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ class ScalableSelectorMixIn:
455455
# see issue #18963 for why it's skipped on older OS X versions
456456
@support.requires_mac_ver(10, 5)
457457
@unittest.skipUnless(resource, "Test needs resource module")
458+
@support.requires_resource('cpu')
458459
def test_above_fd_setsize(self):
459460
# A scalable implementation should have no problem with more than
460461
# FD_SETSIZE file descriptors. Since we don't know the value, we just

Lib/test/test_source_encoding.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import unittest
4-
from test.support import script_helper, captured_stdout, requires_subprocess
4+
from test.support import script_helper, captured_stdout, requires_subprocess, requires_resource
55
from test.support.os_helper import TESTFN, unlink, rmtree
66
from test.support.import_helper import unload
77
import importlib
@@ -250,6 +250,7 @@ def test_crcrcrlf2(self):
250250
class UTF8ValidatorTest(unittest.TestCase):
251251
@unittest.skipIf(not sys.platform.startswith("linux"),
252252
"Too slow to run on non-Linux platforms")
253+
@requires_resource('cpu')
253254
def test_invalid_utf8(self):
254255
# This is a port of test_utf8_decode_invalid_sequences in
255256
# test_unicode.py to exercise the separate utf8 validator in

Lib/test/test_statistics.py

+2
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,7 @@ def test_integer_sqrt_of_frac_rto(self):
21452145
self.assertTrue(m * (r - 1)**2 < n < m * (r + 1)**2)
21462146

21472147
@requires_IEEE_754
2148+
@support.requires_resource('cpu')
21482149
def test_float_sqrt_of_frac(self):
21492150

21502151
def is_root_correctly_rounded(x: Fraction, root: float) -> bool:
@@ -2849,6 +2850,7 @@ def test_cdf(self):
28492850
self.assertTrue(math.isnan(X.cdf(float('NaN'))))
28502851

28512852
@support.skip_if_pgo_task
2853+
@support.requires_resource('cpu')
28522854
def test_inv_cdf(self):
28532855
NormalDist = self.module.NormalDist
28542856

Lib/test/test_subprocess.py

+1
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,7 @@ def test_bufsize_equal_one_binary_mode(self):
12921292
with self.assertWarnsRegex(RuntimeWarning, 'line buffering'):
12931293
self._test_bufsize_equal_one(line, b'', universal_newlines=False)
12941294

1295+
@support.requires_resource('cpu')
12951296
def test_leaking_fds_on_error(self):
12961297
# see bug #5179: Popen leaks file descriptors to PIPEs if
12971298
# the child fails to execute; this will eventually exhaust

Lib/test/test_support.py

+1
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ def check_options(self, args, func, expected=None):
497497
self.assertEqual(proc.stdout.rstrip(), repr(expected))
498498
self.assertEqual(proc.returncode, 0)
499499

500+
@support.requires_resource('cpu')
500501
def test_args_from_interpreter_flags(self):
501502
# Test test.support.args_from_interpreter_flags()
502503
for opts in (

Lib/test/test_sys_settrace.py

+1
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,7 @@ def test_jump_extended_args_unpack_ex_tricky(output):
28342834
) = output.append(4) or "Spam"
28352835
output.append(5)
28362836

2837+
@support.requires_resource('cpu')
28372838
def test_jump_extended_args_for_iter(self):
28382839
# In addition to failing when extended arg handling is broken, this can
28392840
# also hang for a *very* long time:

Lib/test/test_tools/test_freeze.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
@support.skip_if_buildbot('not all buildbots have enough space')
1818
class TestFreeze(unittest.TestCase):
1919

20+
@support.requires_resource('cpu') # Building Python is slow
2021
def test_freeze_simple_script(self):
21-
# Building Python is slow
22-
support.requires('cpu')
23-
2422
script = textwrap.dedent("""
2523
import sys
2624
print('running...')

Lib/test/test_trace.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from pickle import dump
33
import sys
4-
from test.support import captured_stdout
4+
from test.support import captured_stdout, requires_resource
55
from test.support.os_helper import (TESTFN, rmtree, unlink)
66
from test.support.script_helper import assert_python_ok, assert_python_failure
77
import textwrap
@@ -367,6 +367,7 @@ def _coverage(self, tracer,
367367
r = tracer.results()
368368
r.write_results(show_missing=True, summary=True, coverdir=TESTFN)
369369

370+
@requires_resource('cpu')
370371
def test_coverage(self):
371372
tracer = trace.Trace(trace=0, count=1)
372373
with captured_stdout() as stdout:

0 commit comments

Comments
 (0)