Skip to content

Commit 4f394c2

Browse files
[3.11] 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 <storchaka@gmail.com>
1 parent 6538bcf commit 4f394c2

30 files changed

+53
-5
lines changed

Lib/test/_test_multiprocessing.py

+2
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ def test_set_executable(self):
328328
p.join()
329329
self.assertEqual(p.exitcode, 0)
330330

331+
@support.requires_resource('cpu')
331332
def test_args_argument(self):
332333
# bpo-45735: Using list or tuple as *args* in constructor could
333334
# achieve the same effect.
@@ -4470,6 +4471,7 @@ def test_finalize(self):
44704471
result = [obj for obj in iter(conn.recv, 'STOP')]
44714472
self.assertEqual(result, ['a', 'b', 'd10', 'd03', 'd02', 'd01', 'e'])
44724473

4474+
@support.requires_resource('cpu')
44734475
def test_thread_safety(self):
44744476
# bpo-24484: _run_finalizers() should be thread-safe
44754477
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
@@ -1701,6 +1701,7 @@ def test_tuple(self):
17011701
def test_nameconstant(self):
17021702
self.expr(ast.NameConstant(4))
17031703

1704+
@support.requires_resource('cpu')
17041705
def test_stdlib_validates(self):
17051706
stdlib = os.path.dirname(ast.__file__)
17061707
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
@@ -1019,6 +1019,7 @@ def match(req, flag):
10191019
ndim=ndim, shape=shape, strides=strides,
10201020
lst=lst, sliced=sliced)
10211021

1022+
@support.requires_resource('cpu')
10221023
def test_ndarray_getbuf(self):
10231024
requests = (
10241025
# distinct flags
@@ -2750,6 +2751,7 @@ def iter_roundtrip(ex, m, items, fmt):
27502751
m = memoryview(ex)
27512752
iter_roundtrip(ex, m, items, fmt)
27522753

2754+
@support.requires_resource('cpu')
27532755
def test_memoryview_cast_1D_ND(self):
27542756
# Cast between C-contiguous buffers. At least one buffer must
27552757
# 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
@@ -918,6 +918,7 @@ def test_filter_pickle(self):
918918
f2 = filter(filter_char, "abcdeabcde")
919919
self.check_iter_pickle(f1, list(f2), proto)
920920

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

Lib/test/test_compile.py

+1
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ def test_path_like_objects(self):
741741
# An implicit test for PyUnicode_FSDecoder().
742742
compile("42", FakePath("test_compile_pathlike"), "single")
743743

744+
@support.requires_resource('cpu')
744745
def test_stack_overflow(self):
745746
# bpo-31113: Stack overflow when compile a long sequence of
746747
# 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.py

+1
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ def test_idle_thread_reuse(self):
946946
executor.shutdown(wait=True)
947947

948948
@unittest.skipUnless(hasattr(os, 'register_at_fork'), 'need os.register_at_fork')
949+
@support.requires_resource('cpu')
949950
def test_hang_global_shutdown_lock(self):
950951
# bpo-45021: _global_shutdown_lock should be reinitialized in the child
951952
# 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
@@ -15,9 +15,11 @@
1515

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

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

Lib/test/test_descr.py

+1
Original file line numberDiff line numberDiff line change
@@ -4453,6 +4453,7 @@ class Oops(object):
44534453
o.whatever = Provoker(o)
44544454
del o
44554455

4456+
@support.requires_resource('cpu')
44564457
def test_wrapper_segfault(self):
44574458
# SF 927248: deeply nested wrappers could cause stack overflow
44584459
f = lambda:None

Lib/test/test_email/test_email.py

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

42+
from test import support
4243
from test.support import threading_helper
4344
from test.support.os_helper import unlink
4445
from test.test_email import openfile, TestEmailBase
@@ -3342,6 +3343,7 @@ def test_getaddresses_header_obj(self):
33423343
self.assertEqual(addrs[0][1], 'aperson@dom.ain')
33433344

33443345
@threading_helper.requires_working_threading()
3346+
@support.requires_resource('cpu')
33453347
def test_make_msgid_collisions(self):
33463348
# Test make_msgid uniqueness, even with multiple threads
33473349
class MsgidsThread(Thread):

Lib/test/test_exceptions.py

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

13051305

13061306
@cpython_only
1307+
@support.requires_resource('cpu')
13071308
def test_trashcan_recursion(self):
13081309
# See bpo-33930
13091310

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_itertools.py

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

22312231
@support.skip_if_pgo_task
2232+
@support.requires_resource('cpu')
22322233
def test_long_chain_of_empty_iterables(self):
22332234
# Make sure itertools.chain doesn't run into recursion limits when
22342235
# 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
@@ -3,6 +3,7 @@
33
import textwrap
44
import unittest
55

6+
from test import support
67
from test.support.bytecode_helper import BytecodeTestCase
78

89

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

527+
@support.requires_resource('cpu')
526528
def test_format_combinations(self):
527529
flags = '-+ #0'
528530
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
@@ -449,6 +449,7 @@ class ScalableSelectorMixIn:
449449
# see issue #18963 for why it's skipped on older OS X versions
450450
@support.requires_mac_ver(10, 5)
451451
@unittest.skipUnless(resource, "Test needs resource module")
452+
@support.requires_resource('cpu')
452453
def test_above_fd_setsize(self):
453454
# A scalable implementation should have no problem with more than
454455
# 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: koi8-r -*-
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
@@ -251,6 +251,7 @@ def test_crcrcrlf2(self):
251251
class UTF8ValidatorTest(unittest.TestCase):
252252
@unittest.skipIf(not sys.platform.startswith("linux"),
253253
"Too slow to run on non-Linux platforms")
254+
@requires_resource('cpu')
254255
def test_invalid_utf8(self):
255256
# This is a port of test_utf8_decode_invalid_sequences in
256257
# test_unicode.py to exercise the separate utf8 validator in

Lib/test/test_statistics.py

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

21412141
@requires_IEEE_754
2142+
@support.requires_resource('cpu')
21422143
def test_float_sqrt_of_frac(self):
21432144

21442145
def is_root_correctly_rounded(x: Fraction, root: float) -> bool:
@@ -2744,6 +2745,7 @@ def test_cdf(self):
27442745
self.assertTrue(math.isnan(X.cdf(float('NaN'))))
27452746

27462747
@support.skip_if_pgo_task
2748+
@support.requires_resource('cpu')
27472749
def test_inv_cdf(self):
27482750
NormalDist = self.module.NormalDist
27492751

Lib/test/test_subprocess.py

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

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

Lib/test/test_support.py

+1
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ def check_options(self, args, func, expected=None):
510510
self.assertEqual(proc.stdout.rstrip(), repr(expected))
511511
self.assertEqual(proc.returncode, 0)
512512

513+
@support.requires_resource('cpu')
513514
def test_args_from_interpreter_flags(self):
514515
# Test test.support.args_from_interpreter_flags()
515516
for opts in (

Lib/test/test_sys_settrace.py

+1
Original file line numberDiff line numberDiff line change
@@ -2769,6 +2769,7 @@ def test_jump_extended_args_unpack_ex_tricky(output):
27692769
) = output.append(4) or "Spam"
27702770
output.append(5)
27712771

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

Lib/test/test_tools/test_freeze.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
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):
2122
script = textwrap.dedent("""
2223
import sys

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
@@ -369,6 +369,7 @@ def _coverage(self, tracer,
369369
r = tracer.results()
370370
r.write_results(show_missing=True, summary=True, coverdir=TESTFN)
371371

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

Lib/test/test_unicodedata.py

+2
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ def test_ucd_510(self):
295295
self.assertTrue("\u1d79".upper()=='\ua77d')
296296
self.assertTrue(".".upper()=='.')
297297

298+
@requires_resource('cpu')
298299
def test_bug_5828(self):
299300
self.assertEqual("\u1d79".lower(), "\u1d79")
300301
# Only U+0000 should have U+0000 as its upper/lower/titlecase variant
@@ -335,6 +336,7 @@ def unistr(data):
335336
return "".join([chr(x) for x in data])
336337

337338
@requires_resource('network')
339+
@requires_resource('cpu')
338340
def test_normalization(self):
339341
TESTDATAFILE = "NormalizationTest.txt"
340342
TESTDATAURL = f"http://www.pythontest.net/unicode/{unicodedata.unidata_version}/{TESTDATAFILE}"

0 commit comments

Comments
 (0)