code: def mock_timing(monkeypatch: MonkeyPatch):
      """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 `_pytest.timing` functions.
  
      Time is static, and only advances through `sleep` calls, thus tests might sleep over large
      numbers and obtain accurate time() calls at the end, making tests reliable and instant.
      """
  
      @dataclasses.dataclass
      class MockTiming:
          _current_time: float = 1590150050.0
  
          def sleep(self, seconds: float) -> None:
              self._current_time += seconds
  
          def time(self) -> float:
              return self._current_time
  
          def patch(self) -> None:
              from _pytest import timing
  
              monkeypatch.setattr(timing, "sleep", self.sleep)
              monkeypatch.setattr(timing, "time", self.time)
              monkeypatch.setattr(timing, "perf_counter", self.time)
  
      result = MockTiming()
      result.patch()
      return result
  
file_path: pytest/testing/conftest.py
imports: import dataclasses
  import re
  import sys
  from typing import Generator
  from typing import List
  import pytest
  from _pytest.monkeypatch import MonkeyPatch
  from _pytest.pytester import Pytester
label_desc: Use image node_id 8 for calling a global function with example usage: mock_timing(monkeypatch) and returns: result, self