MCPcopy Create free account
hub / github.com/livekit/agents / _virtual_wall_clock

Function _virtual_wall_clock

tests/virtual_time.py:338–360  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

336
337@pytest.fixture(autouse=True)
338def _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
363def add_realtime_option(parser: pytest.Parser) -> None:

Callers

nothing calls this directly

Calls 2

is_virtual_timeFunction · 0.85
_patched_model_clocksFunction · 0.85

Tested by

no test coverage detected