MCPcopy
hub / github.com/pytest-dev/pytest / mock_timing

Function mock_timing

testing/conftest.py:223–239  ·  view source on GitHub ↗

Mocks _pytest.timing with a known object that can be used to control timing in tests deterministically. pytest itself should always use functions from `_pytest.timing` instead of `time` directly. This then allows us more control over time during testing, if testing code also uses `

(monkeypatch: MonkeyPatch)

Source from the content-addressed store, hash-verified

221
222@pytest.fixture
223def mock_timing(monkeypatch: MonkeyPatch):
224 """Mocks _pytest.timing with a known object that can be used to control timing in tests
225 deterministically.
226
227 pytest itself should always use functions from `_pytest.timing` instead of `time` directly.
228
229 This then allows us more control over time during testing, if testing code also
230 uses `_pytest.timing` functions.
231
232 Time is static, and only advances through `sleep` calls, thus tests might sleep over large
233 numbers and obtain accurate time() calls at the end, making tests reliable and instant.
234 """
235 from _pytest.timing import MockTiming
236
237 result = MockTiming()
238 result.patch(monkeypatch)
239 return result
240
241
242@pytest.fixture(autouse=True)

Callers

nothing calls this directly

Calls 2

patchMethod · 0.95
MockTimingClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…