Point wall-clock reads at the running loop's virtual clock for a `virtual_time` test. No-op unless the test is marked `virtual_time`. Two kinds of reads are covered: - inline `time.time()` / `time.perf_counter()` -- redirected by patching the `time` module (these re-read the attribut
(request: pytest.FixtureRequest)
| 336 | |
| 337 | @pytest.fixture(autouse=True) |
| 338 | def _virtual_wall_clock(request: pytest.FixtureRequest) -> Iterator[None]: |
| 339 | """Point wall-clock reads at the running loop's virtual clock for a `virtual_time` test. |
| 340 | |
| 341 | No-op unless the test is marked `virtual_time`. Two kinds of reads are covered: |
| 342 | |
| 343 | - inline `time.time()` / `time.perf_counter()` -- redirected by patching the `time` |
| 344 | module (these re-read the attribute at call time, so a scoped patch reaches them); |
| 345 | - `default_factory=time.time` captured on event/chat-context models at import -- redirected |
| 346 | by :func:`_patched_model_clocks`, since a module patch cannot reach a captured reference. |
| 347 | |
| 348 | Both resolve the loop at call time, so reads inside the loop see virtual time while any stray |
| 349 | read from outside it (no running loop) falls back to a stable constant. Scoped to the test. |
| 350 | """ |
| 351 | if not is_virtual_time(request.node): |
| 352 | yield |
| 353 | return |
| 354 | |
| 355 | with ( |
| 356 | mock.patch.object(time, "time", _now), |
| 357 | mock.patch.object(time, "perf_counter", _perf), |
| 358 | _patched_model_clocks(), |
| 359 | ): |
| 360 | yield |
| 361 | |
| 362 | |
| 363 | def add_realtime_option(parser: pytest.Parser) -> None: |
nothing calls this directly
no test coverage detected