@@ -28,22 +28,6 @@ def test_web___all__(pytester: pytest.Pytester) -> None:
2828 result .assert_outcomes (passed = 0 , errors = 0 )
2929
3030
31- _IS_CI_ENV = os .getenv ("CI" ) == "true"
32- _XDIST_WORKER_COUNT = int (os .getenv ("PYTEST_XDIST_WORKER_COUNT" , 0 ))
33- _IS_XDIST_RUN = _XDIST_WORKER_COUNT > 1
34-
35- _TARGET_TIMINGS_BY_PYTHON_VERSION = {
36- "3.12" : (
37- # 3.12+ is expected to be a bit slower due to performance trade-offs,
38- # and even slower under pytest-xdist, especially in CI
39- _XDIST_WORKER_COUNT * 100 * (1 if _IS_CI_ENV else 1.53 )
40- if _IS_XDIST_RUN
41- else 295
42- ),
43- }
44- _TARGET_TIMINGS_BY_PYTHON_VERSION ["3.13" ] = _TARGET_TIMINGS_BY_PYTHON_VERSION ["3.12" ]
45-
46-
4731@pytest .mark .internal
4832@pytest .mark .dev_mode
4933@pytest .mark .skipif (
@@ -57,7 +41,10 @@ def test_import_time(pytester: pytest.Pytester) -> None:
5741 Obviously, the time may vary on different machines and may need to be adjusted
5842 from time to time, but this should provide an early warning if something is
5943 added that significantly increases import time.
44+
45+ Runs 3 times and keeps the minimum time to reduce flakiness.
6046 """
47+ IMPORT_TIME_THRESHOLD_MS = 300 if sys .version_info >= (3 , 12 ) else 200
6148 root = Path (__file__ ).parent .parent
6249 old_path = os .environ .get ("PYTHONPATH" )
6350 os .environ ["PYTHONPATH" ] = os .pathsep .join ([str (root )] + sys .path )
@@ -67,18 +54,12 @@ def test_import_time(pytester: pytest.Pytester) -> None:
6754 try :
6855 for _ in range (3 ):
6956 r = pytester .run (sys .executable , "-We" , "-c" , cmd )
70-
71- assert not r .stderr .str ()
72- runtime_ms = int (r .stdout .str ())
73- if runtime_ms < best_time_ms :
74- best_time_ms = runtime_ms
57+ assert not r .stderr .str (), r .stderr .str ()
58+ best_time_ms = min (best_time_ms , int (r .stdout .str ()))
7559 finally :
7660 if old_path is None :
7761 os .environ .pop ("PYTHONPATH" )
7862 else :
7963 os .environ ["PYTHONPATH" ] = old_path
8064
81- expected_time = _TARGET_TIMINGS_BY_PYTHON_VERSION .get (
82- f"{ sys .version_info .major } .{ sys .version_info .minor } " , 200
83- )
84- assert best_time_ms < expected_time
65+ assert best_time_ms < IMPORT_TIME_THRESHOLD_MS
0 commit comments