Visitar URL original
gh-108416: Mark slow test methods with @requires_resource('cpu') by serhiy-storchaka · Pull Request #108421 · python/cpython · GitHub
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
Prev Previous commit
Next Next commit
Only mark tests which spend significant system or user time.
  • Loading branch information
serhiy-storchaka committed Aug 25, 2023
commit 8712734c833b80ba98836fcf5daf9ae56a374e20
3 changes: 0 additions & 3 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ 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 @@ -4992,7 +4991,6 @@ 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 @@ -5021,7 +5019,6 @@ 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: 0 additions & 1 deletion Lib/test/test_concurrent_futures/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ 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
3 changes: 0 additions & 3 deletions Lib/test/test_concurrent_futures/test_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import time
import unittest
from concurrent import futures
from test import support

from .util import (
CANCELLED_FUTURE, CANCELLED_AND_NOTIFIED_FUTURE, EXCEPTION_FUTURE,
Expand Down Expand Up @@ -54,7 +53,6 @@ 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 @@ -112,7 +110,6 @@ 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
2 changes: 2 additions & 0 deletions Lib/test/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import unittest
import weakref
from test import support
from test.support import threading_helper

try:
Expand Down Expand Up @@ -570,6 +571,7 @@ def test_hamt_collision_3(self):

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

@support.requires_resource('cpu')
def test_hamt_stress(self):
COLLECTION_SIZE = 7000
TEST_ITERS_EVERY = 647
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_eintr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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
1 change: 0 additions & 1 deletion Lib/test/test_faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,6 @@ 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
1 change: 0 additions & 1 deletion Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,6 @@ 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: 1 addition & 4 deletions 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, requires_resource
from test.support import verbose, run_with_tz, run_with_locale, cpython_only
from test.support import hashlib_helper
from test.support import threading_helper
import unittest
Expand Down Expand Up @@ -456,7 +456,6 @@ 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 @@ -550,7 +549,6 @@ 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 @@ -565,7 +563,6 @@ 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
6 changes: 0 additions & 6 deletions Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4468,12 +4468,10 @@ 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 @@ -4647,13 +4645,11 @@ 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 @@ -4727,12 +4723,10 @@ 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: 0 additions & 1 deletion Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ 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
2 changes: 2 additions & 0 deletions Lib/test/test_peepholer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import textwrap
import unittest

from test import support
from test.support.bytecode_helper import BytecodeTestCase, CfgOptimizationTestCase


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

@support.requires_resource('cpu')
def test_format_combinations(self):
flags = '-+ #0'
testcases = [
Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import time
import unittest
from test.support import (
cpython_only, requires_subprocess, requires_working_socket, requires_resource
cpython_only, requires_subprocess, requires_working_socket
)
from test.support import threading_helper
from test.support.os_helper import TESTFN
Expand Down Expand Up @@ -124,7 +124,6 @@ def fileno(self):
# select(), modified to use poll() instead.

@requires_subprocess()
@requires_resource('cpu')
def test_poll2(self):
cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_runpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import textwrap
import unittest
import warnings
from test.support import no_tracing, verbose, requires_subprocess
from test.support import no_tracing, verbose, requires_subprocess, requires_resource
from test.support.import_helper import forget, make_legacy_pyc, unload
from test.support.os_helper import create_empty_file, temp_dir
from test.support.script_helper import make_script, make_zip_script
Expand Down Expand Up @@ -733,6 +733,7 @@ def test_zipfile_error(self):
self._check_import_error(zip_name, msg)

@no_tracing
@requires_resource('cpu')
def test_main_recursion_error(self):
with temp_dir() as script_dir, temp_dir() as dummy_dir:
mod_name = '__main__'
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,6 @@ def test_siginterrupt_on(self):
interrupted = self.readpipe_interrupted(True)
self.assertTrue(interrupted)

@support.requires_resource('cpu')
def test_siginterrupt_off(self):
# If a signal handler is installed and siginterrupt is called with
# a false value for the second argument, when that signal arrives, it
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_smtpnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def test_connect_default_port(self):
server.ehlo()
server.quit()

@support.requires_resource('cpu')
def test_connect_using_sslcontext(self):
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.check_hostname = False
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,6 @@ def test_timeout_connect_ex(self):
self.assertIn(rc, (errno.EAGAIN, errno.EWOULDBLOCK))

@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'Needs IPv6')
@support.requires_resource('cpu')
def test_get_server_certificate_ipv6(self):
with socket_helper.transient_internet('ipv6.google.com'):
_test_get_server_certificate(self, 'ipv6.google.com', 443)
Expand Down Expand Up @@ -2741,7 +2740,6 @@ def try_protocol_combo(server_protocol, client_protocol, expect_success,

class ThreadedTests(unittest.TestCase):

@support.requires_resource('cpu')
def test_echo(self):
"""Basic test of an SSL client connecting to a server"""
if support.verbose:
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ def test_check_output_stdin_with_input_arg(self):
self.assertIn('stdin', c.exception.args[0])
self.assertIn('input', c.exception.args[0])

@support.requires_resource('cpu')
def test_check_output_timeout(self):
# check_output() function with timeout arg
with self.assertRaises(subprocess.TimeoutExpired) as c:
Expand Down Expand Up @@ -1644,7 +1643,6 @@ def test_check_output_stdin_with_input_arg(self):
self.assertIn('stdin', c.exception.args[0])
self.assertIn('input', c.exception.args[0])

@support.requires_resource('cpu')
def test_check_output_timeout(self):
with self.assertRaises(subprocess.TimeoutExpired) as c:
cp = self.run_python((
Expand Down
4 changes: 1 addition & 3 deletions Lib/test/test_tools/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
@support.skip_if_buildbot('not all buildbots have enough space')
class TestFreeze(unittest.TestCase):

@support.requires_resource('cpu') # Building Python is slow
def test_freeze_simple_script(self):
# Building Python is slow
support.requires('cpu')

script = textwrap.dedent("""
import sys
print('running...')
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ def __str__(self):
self.assertEqual(err[0], "%s: %s\n" % (str_name, str_value))

@requires_subprocess()
@support.requires_resource('cpu')
def test_encoded_file(self):
# Test that tracebacks are correctly printed for encoded source files:
# - correct line number (Issue2384)
Expand Down
5 changes: 0 additions & 5 deletions Lib/test/test_urllib2net.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ def setUp(self):
# XXX The rest of these tests aren't very good -- they don't check much.
# They do sometimes catch some major disasters, though.

@support.requires_resource('cpu')
def test_ftp(self):
# Testing the same URL twice exercises the caching in CacheFTPHandler
urls = [
Expand Down Expand Up @@ -197,7 +196,6 @@ def test_urlwithfrag(self):
self.assertEqual(res.geturl(),
"http://www.pythontest.net/index.html#frag")

@support.requires_resource('cpu')
def test_redirect_url_withfrag(self):
redirect_url_with_frag = "http://www.pythontest.net/redir/with_frag/"
with socket_helper.transient_internet(redirect_url_with_frag):
Expand Down Expand Up @@ -336,7 +334,6 @@ def test_http_timeout(self):

FTP_HOST = 'ftp://www.pythontest.net/'

@support.requires_resource('cpu')
def test_ftp_basic(self):
self.assertIsNone(socket.getdefaulttimeout())
with socket_helper.transient_internet(self.FTP_HOST, timeout=None):
Expand All @@ -355,7 +352,6 @@ def test_ftp_default_timeout(self):
socket.setdefaulttimeout(None)
self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)

@support.requires_resource('cpu')
def test_ftp_no_timeout(self):
self.assertIsNone(socket.getdefaulttimeout())
with socket_helper.transient_internet(self.FTP_HOST):
Expand All @@ -367,7 +363,6 @@ def test_ftp_no_timeout(self):
socket.setdefaulttimeout(None)
self.assertIsNone(u.fp.fp.raw._sock.gettimeout())

@support.requires_resource('cpu')
def test_ftp_timeout(self):
with socket_helper.transient_internet(self.FTP_HOST):
u = _urlopen_with_retry(self.FTP_HOST, timeout=60)
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_urllibnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def test_getcode(self):
open_url.close()
self.assertEqual(code, 404)

@support.requires_resource('cpu')
def test_bad_address(self):
# Make sure proper exception is raised when connecting to a bogus
# address.
Expand Down Expand Up @@ -192,7 +191,6 @@ def test_header(self):

logo = "http://www.pythontest.net/"

@support.requires_resource('cpu')
def test_data_header(self):
with self.urlretrieve(self.logo) as (file_location, fileheaders):
datevalue = fileheaders.get('Date')
Expand Down
9 changes: 0 additions & 9 deletions Lib/test/test_xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,47 +1037,38 @@ def test_path2(self):
self.assertEqual(p.add(6,8), 6+8)
self.assertRaises(xmlrpclib.Fault, p.pow, 6, 8)

@support.requires_resource('cpu')
def test_path3(self):
p = xmlrpclib.ServerProxy(URL+"/is/broken")
self.assertRaises(xmlrpclib.Fault, p.add, 6, 8)

@support.requires_resource('cpu')
def test_invalid_path(self):
p = xmlrpclib.ServerProxy(URL+"/invalid")
self.assertRaises(xmlrpclib.Fault, p.add, 6, 8)

@support.requires_resource('cpu')
def test_path_query_fragment(self):
p = xmlrpclib.ServerProxy(URL+"/foo?k=v#frag")
self.assertEqual(p.test(), "/foo?k=v#frag")

@support.requires_resource('cpu')
def test_path_fragment(self):
p = xmlrpclib.ServerProxy(URL+"/foo#frag")
self.assertEqual(p.test(), "/foo#frag")

@support.requires_resource('cpu')
def test_path_query(self):
p = xmlrpclib.ServerProxy(URL+"/foo?k=v")
self.assertEqual(p.test(), "/foo?k=v")

@support.requires_resource('cpu')
def test_empty_path(self):
p = xmlrpclib.ServerProxy(URL)
self.assertEqual(p.test(), "/RPC2")

@support.requires_resource('cpu')
def test_root_path(self):
p = xmlrpclib.ServerProxy(URL + "/")
self.assertEqual(p.test(), "/")

@support.requires_resource('cpu')
def test_empty_path_query(self):
p = xmlrpclib.ServerProxy(URL + "?k=v")
self.assertEqual(p.test(), "?k=v")

@support.requires_resource('cpu')
def test_empty_path_fragment(self):
p = xmlrpclib.ServerProxy(URL + "#frag")
self.assertEqual(p.test(), "#frag")
Expand Down