Skip to content

Commit 4425705

Browse files
committed
Move is_slow_machine to test_support
1 parent 4f18889 commit 4425705

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Lib/test/support/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import sysconfig
1717
import textwrap
1818
import time
19+
import timeit
1920
import types
2021
import unittest
2122
import warnings
@@ -2694,6 +2695,9 @@ def exceeds_recursion_limit():
26942695
return 150_000
26952696

26962697

2698+
# Is the host running the tests significantly slower than a typical PC?
2699+
is_slow_machine = timeit.timeit("2*2", number=10_000) > 0.0001
2700+
26972701
# Windows doesn't have os.uname() but it doesn't support s390x.
26982702
is_s390x = hasattr(os, 'uname') and os.uname().machine == 's390x'
26992703
skip_on_s390x = unittest.skipIf(is_s390x, 'skipped on s390x')

Lib/test/test_profiling/test_sampling_profiler.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import subprocess
1111
import sys
1212
import tempfile
13-
import timeit
1413
import unittest
1514
from collections import namedtuple
1615
from unittest import mock
@@ -26,12 +25,10 @@
2625
from test.support import force_not_colorized_test_class, SHORT_TIMEOUT
2726
from test.support.socket_helper import find_unused_port
2827
from test.support import requires_subprocess, is_emscripten
29-
from test.support import captured_stdout, captured_stderr
28+
from test.support import captured_stdout, captured_stderr, is_slow_machine
3029

3130
PROCESS_VM_READV_SUPPORTED = False
3231

33-
SLOW_MACHINE = timeit.timeit("2*2", number=10_000) > 0.0001
34-
3532
try:
3633
from _remote_debugging import PROCESS_VM_READV_SUPPORTED
3734
import _remote_debugging
@@ -1757,7 +1754,7 @@ def main_loop():
17571754
'''
17581755

17591756
def test_sampling_basic_functionality(self):
1760-
duration_sec = 10 if SLOW_MACHINE else 2
1757+
duration_sec = 10 if is_slow_machine else 2
17611758
with (
17621759
test_subprocess(self.test_script) as subproc,
17631760
io.StringIO() as captured_output,
@@ -1908,7 +1905,7 @@ def test_sample_target_script(self):
19081905
script_file.flush()
19091906
self.addCleanup(close_and_unlink, script_file)
19101907

1911-
duration = 10 if SLOW_MACHINE else 1
1908+
duration = 10 if is_slow_machine else 1
19121909
test_args = [
19131910
"profiling.sampling.sample", "-d", str(duration), script_file.name
19141911
]
@@ -1943,7 +1940,7 @@ def test_sample_target_module(self):
19431940
with open(module_path, "w") as f:
19441941
f.write(self.test_script)
19451942

1946-
duration = 10 if SLOW_MACHINE else 1
1943+
duration = 10 if is_slow_machine else 1
19471944
test_args = [
19481945
"profiling.sampling.sample",
19491946
"-d", str(duration),

0 commit comments

Comments
 (0)