9
9
import platform
10
10
import re
11
11
import sys
12
- import time
12
+ import time as _time_module
13
13
import warnings
14
14
from pathlib import Path
15
15
from typing import TYPE_CHECKING , Any , Callable
@@ -74,6 +74,12 @@ class UnexpectedError(Exception):
74
74
resource .setrlimit (resource .RLIMIT_AS , (memory_limit , memory_limit ))
75
75
76
76
77
+ # Store references to original functions before any patching
78
+ _ORIGINAL_TIME_TIME = _time_module .time
79
+ _ORIGINAL_PERF_COUNTER = _time_module .perf_counter
80
+ _ORIGINAL_TIME_SLEEP = _time_module .sleep
81
+
82
+
77
83
# Apply deterministic patches for reproducible test execution
78
84
def _apply_deterministic_patches () -> None :
79
85
"""Apply patches to make all sources of randomness deterministic."""
@@ -82,7 +88,7 @@ def _apply_deterministic_patches() -> None:
82
88
import time
83
89
import uuid
84
90
85
- # Store original functions
91
+ # Store original functions (these are already saved globally above)
86
92
_original_time = time .time
87
93
_original_perf_counter = time .perf_counter
88
94
_original_datetime_now = datetime .datetime .now
@@ -269,7 +275,7 @@ def pytest_runtestloop(self, session: Session) -> bool:
269
275
if session .config .option .collectonly :
270
276
return True
271
277
272
- start_time : float = time . time ()
278
+ start_time : float = _ORIGINAL_TIME_TIME ()
273
279
total_time : float = self ._get_total_time (session )
274
280
275
281
count : int = 0
@@ -296,7 +302,7 @@ def pytest_runtestloop(self, session: Session) -> bool:
296
302
raise session .Interrupted (session .shouldstop )
297
303
if self ._timed_out (session , start_time , count ):
298
304
break # exit loop
299
- time . sleep (self ._get_delay_time (session ))
305
+ _ORIGINAL_TIME_SLEEP (self ._get_delay_time (session ))
300
306
return True
301
307
302
308
def _clear_lru_caches (self , item : pytest .Item ) -> None :
@@ -395,7 +401,7 @@ def _timed_out(self, session: Session, start_time: float, count: int) -> bool:
395
401
"""
396
402
return count >= session .config .option .codeflash_max_loops or (
397
403
count >= session .config .option .codeflash_min_loops
398
- and time . time () - start_time > self ._get_total_time (session )
404
+ and _ORIGINAL_TIME_TIME () - start_time > self ._get_total_time (session )
399
405
)
400
406
401
407
@pytest .fixture
0 commit comments