Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-108416: Mark slow test methods with @requires_resource('cpu')
  • Loading branch information
serhiy-storchaka committed Aug 24, 2023
commit 3147ba9d36af9bf039c35f031f0617bcb84ff37b
5 changes: 5 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ def test_set_executable(self):
p.join()
self.assertEqual(p.exitcode, 0)

@support.requires_resource('cpu')
def test_args_argument(self):
# bpo-45735: Using list or tuple as *args* in constructor could
# achieve the same effect.
Expand Down Expand Up @@ -674,6 +675,7 @@ def test_close(self):

close_queue(q)

@support.requires_resource('cpu')
def test_many_processes(self):
if self.TYPE == 'threads':
self.skipTest('test not appropriate for {}'.format(self.TYPE))
Expand Down Expand Up @@ -4504,6 +4506,7 @@ def test_finalize(self):
result = [obj for obj in iter(conn.recv, 'STOP')]
self.assertEqual(result, ['a', 'b', 'd10', 'd03', 'd02', 'd01', 'e'])

@support.requires_resource('cpu')
def test_thread_safety(self):
# bpo-24484: _run_finalizers() should be thread-safe
def cb():
Expand Down Expand Up @@ -4989,6 +4992,7 @@ def test_wait_slow(self):
def test_wait_socket_slow(self):
self.test_wait_socket(True)

@support.requires_resource('cpu')
def test_wait_timeout(self):
from multiprocessing.connection import wait

Expand Down Expand Up @@ -5017,6 +5021,7 @@ def signal_and_sleep(cls, sem, period):
sem.release()
time.sleep(period)

@support.requires_resource('cpu')
def test_wait_integer(self):
from multiprocessing.connection import wait

Expand Down
1 change: 1 addition & 0 deletions Lib/test/pickletester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,7 @@ def check_frame_opcodes(self, pickled):
self.assertLess(pos - frameless_start, self.FRAME_SIZE_MIN)

@support.skip_if_pgo_task
@support.requires_resource('cpu')
def test_framing_many_objects(self):
obj = list(range(10**5))
for proto in range(4, pickle.HIGHEST_PROTOCOL + 1):
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,7 @@ def test_nameconstant(self):
'ast.NameConstant is deprecated and will be removed in Python 3.14; use ast.Constant instead',
])

@support.requires_resource('cpu')
def test_stdlib_validates(self):
stdlib = os.path.dirname(ast.__file__)
tests = [fn for fn in os.listdir(stdlib) if fn.endswith(".py")]
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ def match(req, flag):
ndim=ndim, shape=shape, strides=strides,
lst=lst, sliced=sliced)

@support.requires_resource('cpu')
def test_ndarray_getbuf(self):
requests = (
# distinct flags
Expand Down Expand Up @@ -2760,6 +2761,7 @@ def iter_roundtrip(ex, m, items, fmt):
m = memoryview(ex)
iter_roundtrip(ex, m, items, fmt)

@support.requires_resource('cpu')
def test_memoryview_cast_1D_ND(self):
# Cast between C-contiguous buffers. At least one buffer must
# be 1D, at least one format must be 'c', 'b' or 'B'.
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ def test_filter_pickle(self):
f2 = filter(filter_char, "abcdeabcde")
self.check_iter_pickle(f1, list(f2), proto)

@support.requires_resource('cpu')
def test_filter_dealloc(self):
# Tests recursive deallocation of nested filter objects using the
# thrashcan mechanism. See gh-102356 for more details.
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ def test_path_like_objects(self):
# An implicit test for PyUnicode_FSDecoder().
compile("42", FakePath("test_compile_pathlike"), "single")

@support.requires_resource('cpu')
def test_stack_overflow(self):
# bpo-31113: Stack overflow when compile a long sequence of
# complex statements.
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_compileall.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ def test_no_args_compiles_path(self):
self.assertNotCompiled(self.barfn)

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

@support.requires_resource('cpu')
def test_no_args_respects_quiet_flag(self):
script_helper.make_script(self.directory, 'baz', '')
with self.temporary_pycache_prefix() as env:
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_concurrent_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ def test_first_completed_some_already_completed(self):
finished)
self.assertEqual(set([future1]), pending)

@support.requires_resource('cpu')
def test_first_exception(self):
future1 = self.executor.submit(mul, 2, 21)
future2 = self.executor.submit(sleep_and_raise, 1.5)
Expand Down Expand Up @@ -695,6 +696,7 @@ def test_all_completed(self):
future2]), finished)
self.assertEqual(set(), pending)

@support.requires_resource('cpu')
def test_timeout(self):
future1 = self.executor.submit(mul, 6, 7)
future2 = self.executor.submit(time.sleep, 6)
Expand Down Expand Up @@ -859,6 +861,7 @@ def test_map_exception(self):
self.assertEqual(i.__next__(), (0, 1))
self.assertRaises(ZeroDivisionError, i.__next__)

@support.requires_resource('cpu')
def test_map_timeout(self):
results = []
try:
Expand Down Expand Up @@ -951,6 +954,7 @@ def test_idle_thread_reuse(self):
executor.shutdown(wait=True)

@unittest.skipUnless(hasattr(os, 'register_at_fork'), 'need os.register_at_fork')
@support.requires_resource('cpu')
def test_hang_global_shutdown_lock(self):
# bpo-45021: _global_shutdown_lock should be reinitialized in the child
# process, otherwise it will never exit
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_cppext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

@support.requires_subprocess()
class TestCPPExt(unittest.TestCase):
@support.requires_resource('cpu')
def test_build_cpp11(self):
self.check_build(False, '_testcpp11ext')

@support.requires_resource('cpu')
def test_build_cpp03(self):
self.check_build(True, '_testcpp03ext')

Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4457,6 +4457,7 @@ class Oops(object):
o.whatever = Provoker(o)
del o

@support.requires_resource('cpu')
def test_wrapper_segfault(self):
# SF 927248: deeply nested wrappers could cause stack overflow
f = lambda:None
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_eintr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class EINTRTests(unittest.TestCase):

@unittest.skipUnless(hasattr(signal, "setitimer"), "requires setitimer()")
@support.requires_resource('cpu')
def test_all(self):
# Run the tester in a sub-process, to make sure there is only one
# thread (for reliable signal delivery).
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from email import quoprimime
from email import utils

from test import support
from test.support import threading_helper
from test.support.os_helper import unlink
from test.test_email import openfile, TestEmailBase
Expand Down Expand Up @@ -3358,6 +3359,7 @@ def test_getaddresses_header_obj(self):
self.assertEqual(addrs[0][1], 'aperson@dom.ain')

@threading_helper.requires_working_threading()
@support.requires_resource('cpu')
def test_make_msgid_collisions(self):
# Test make_msgid uniqueness, even with multiple threads
class MsgidsThread(Thread):
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ def g():


@cpython_only
@support.requires_resource('cpu')
def test_trashcan_recursion(self):
# See bpo-33930

Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ def test_dump_traceback_later_fd(self):
with tempfile.TemporaryFile('wb+') as fp:
self.check_dump_traceback_later(fd=fp.fileno())

@support.requires_resource('cpu')
def test_dump_traceback_later_twice(self):
self.check_dump_traceback_later(loops=2)

Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def assertGdbRepr(self, val, exp_repr=None):
('%r did not equal expected %r; full output was:\n%s'
% (gdb_repr, exp_repr, gdb_output)))

@support.requires_resource('cpu')
def test_int(self):
'Verify the pretty-printing of various int values'
self.assertGdbRepr(42)
Expand All @@ -343,6 +344,7 @@ def test_lists(self):
self.assertGdbRepr([])
self.assertGdbRepr(list(range(5)))

@support.requires_resource('cpu')
def test_bytes(self):
'Verify the pretty-printing of bytes'
self.assertGdbRepr(b'')
Expand All @@ -357,6 +359,7 @@ def test_bytes(self):

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

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

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

@support.requires_resource('cpu')
def test_frozensets(self):
'Verify the pretty-printing of frozensets'
if (gdb_major_version, gdb_minor_version) < (7, 3):
Expand Down Expand Up @@ -828,6 +833,7 @@ def test_bt_full(self):

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

@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
@support.requires_resource('cpu')
# Some older versions of gdb will fail with
# "Cannot find new threads: generic error"
# unless we add LD_PRELOAD=PATH-TO-libpthread.so.1 as a workaround
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,7 @@ def test_networked_good_cert(self):
h.close()
self.assertIn('nginx', server_string)

@support.requires_resource('cpu')
def test_networked_bad_cert(self):
# We feed a "CA" cert that is unrelated to the server's cert
import ssl
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import threading
import socket

from test.support import verbose, run_with_tz, run_with_locale, cpython_only
from test.support import verbose, run_with_tz, run_with_locale, cpython_only, requires_resource
from test.support import hashlib_helper
from test.support import threading_helper
import unittest
Expand Down Expand Up @@ -456,6 +456,7 @@ def test_simple_with_statement(self):
with self.imap_class(*server.server_address):
pass

@requires_resource('cpu')
def test_imaplib_timeout_test(self):
_, server = self._setup(SimpleIMAPHandler)
addr = server.server_address[1]
Expand Down Expand Up @@ -549,6 +550,7 @@ class NewIMAPSSLTests(NewIMAPTestsMixin, unittest.TestCase):
imap_class = IMAP4_SSL
server_class = SecureTCPServer

@requires_resource('cpu')
def test_ssl_raises(self):
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
self.assertEqual(ssl_context.verify_mode, ssl.CERT_REQUIRED)
Expand All @@ -563,6 +565,7 @@ def test_ssl_raises(self):
ssl_context=ssl_context)
client.shutdown()

@requires_resource('cpu')
def test_ssl_verified(self):
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_context.load_verify_locations(CAFILE)
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,14 @@ class StressTests(TestBase):
# In these tests we generally want a lot of interpreters,
# but not so many that any test takes too long.

@support.requires_resource('cpu')
def test_create_many_sequential(self):
alive = []
for _ in range(100):
interp = interpreters.create()
alive.append(interp)

@support.requires_resource('cpu')
def test_create_many_threaded(self):
alive = []
def task():
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4468,10 +4468,12 @@ def run():
self.assertFalse(err.strip('.!'))

@threading_helper.requires_working_threading()
@support.requires_resource('cpu')
def test_daemon_threads_shutdown_stdout_deadlock(self):
self.check_daemon_threads_shutdown_deadlock('stdout')

@threading_helper.requires_working_threading()
@support.requires_resource('cpu')
def test_daemon_threads_shutdown_stderr_deadlock(self):
self.check_daemon_threads_shutdown_deadlock('stderr')

Expand Down Expand Up @@ -4645,11 +4647,13 @@ def alarm_handler(sig, frame):
os.close(r)

@requires_alarm
@support.requires_resource('cpu')
def test_interrupted_read_retry_buffered(self):
self.check_interrupted_read_retry(lambda x: x.decode('latin1'),
mode="rb")

@requires_alarm
@support.requires_resource('cpu')
def test_interrupted_read_retry_text(self):
self.check_interrupted_read_retry(lambda x: x,
mode="r", encoding="latin1")
Expand Down Expand Up @@ -4723,10 +4727,12 @@ def alarm2(sig, frame):
raise

@requires_alarm
@support.requires_resource('cpu')
def test_interrupted_write_retry_buffered(self):
self.check_interrupted_write_retry(b"x", mode="wb")

@requires_alarm
@support.requires_resource('cpu')
def test_interrupted_write_retry_text(self):
self.check_interrupted_write_retry("x", mode="w", encoding="latin1")

Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,7 @@ def gen2(x):
self.assertEqual(hist, [0,1])

@support.skip_if_pgo_task
@support.requires_resource('cpu')
def test_long_chain_of_empty_iterables(self):
# Make sure itertools.chain doesn't run into recursion limits when
# dealing with long chains of empty iterables. Even with a high
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_largefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import socket
import shutil
import threading
from test.support import requires, bigmemtest
from test.support import requires, bigmemtest, requires_resource
from test.support import SHORT_TIMEOUT
from test.support import socket_helper
from test.support.os_helper import TESTFN, unlink
Expand Down Expand Up @@ -173,6 +173,7 @@ class TestCopyfile(LargeFileTest, unittest.TestCase):
# Exact required disk space would be (size * 2), but let's give it a
# bit more tolerance.
@skip_no_disk_space(TESTFN, size * 2.5)
@requires_resource('cpu')
def test_it(self):
# Internally shutil.copyfile() can use "fast copy" methods like
# os.sendfile().
Expand Down Expand Up @@ -222,6 +223,7 @@ def run(sock):
# Exact required disk space would be (size * 2), but let's give it a
# bit more tolerance.
@skip_no_disk_space(TESTFN, size * 2.5)
@requires_resource('cpu')
def test_it(self):
port = socket_helper.find_unused_port()
with socket.create_server(("", port)) as sock:
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ def test_path_objects(self):
support.is_emscripten, "Emscripten cannot fstat unlinked files."
)
@threading_helper.requires_working_threading()
@support.requires_resource('cpu')
def test_race(self):
# Issue #14632 refers.
def remove_loop(fname, tries):
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_multibytecodec.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def test_iso2022_jp_g0(self):
e = '\u3406'.encode(encoding)
self.assertFalse(any(x > 0x80 for x in e))

@support.requires_resource('cpu')
def test_bug1572832(self):
for x in range(0x10000, 0x110000):
# Any ISO 2022 codec will cause the segfault
Expand Down
Loading