Introduce _pytest.timing as a way to control timing during tests

_pytest.timing is an indirection to 'time' functions, which pytest production
code should use instead of 'time' directly.

'mock_timing' is a new fixture which then mocks those functions, allowing us
to write time-reliable tests which run instantly and are not flaky.

This was triggered by recent flaky junitxml tests on Windows related to timing
issues.
This commit is contained in:
Bruno Oliveira
2020-05-22 16:10:51 -03:00
parent c98bc4cd3d
commit 1780924b27
8 changed files with 94 additions and 68 deletions
+13
View File
@@ -0,0 +1,13 @@
"""
Indirection for time functions.
We intentionally grab some "time" functions internally to avoid tests mocking "time" to affect
pytest runtime information (issue #185).
Fixture "mock_timinig" also interacts with this module for pytest's own tests.
"""
from time import perf_counter
from time import sleep
from time import time
__all__ = ["perf_counter", "sleep", "time"]