@@ -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 (
@@ -56,7 +40,10 @@ def test_import_time(pytester: pytest.Pytester) -> None:
5640 Obviously, the time may vary on different machines and may need to be adjusted
5741 from time to time, but this should provide an early warning if something is
5842 added that significantly increases import time.
43+
44+ Runs 3 times and keeps the minimum time to reduce flakiness.
5945 """
46+ IMPORT_TIME_THRESHOLD_MS = 300 if sys .version_info >= (3 , 12 ) else 200
6047 root = Path (__file__ ).parent .parent
6148 old_path = os .environ .get ("PYTHONPATH" )
6249 os .environ ["PYTHONPATH" ] = os .pathsep .join ([str (root )] + sys .path )
@@ -66,18 +53,12 @@ def test_import_time(pytester: pytest.Pytester) -> None:
6653 try :
6754 for _ in range (3 ):
6855 r = pytester .run (sys .executable , "-We" , "-c" , cmd )
69-
70- assert not r .stderr .str ()
71- runtime_ms = int (r .stdout .str ())
72- if runtime_ms < best_time_ms :
73- best_time_ms = runtime_ms
56+ assert not r .stderr .str (), r .stderr .str ()
57+ best_time_ms = min (best_time_ms , int (r .stdout .str ()))
7458 finally :
7559 if old_path is None :
7660 os .environ .pop ("PYTHONPATH" )
7761 else :
7862 os .environ ["PYTHONPATH" ] = old_path
7963
80- expected_time = _TARGET_TIMINGS_BY_PYTHON_VERSION .get (
81- f"{ sys .version_info .major } .{ sys .version_info .minor } " , 200
82- )
83- assert best_time_ms < expected_time
64+ assert best_time_ms < IMPORT_TIME_THRESHOLD_MS
0 commit comments