diff options
author | Bruno Oliveira <nicoddemus@gmail.com> | 2020-05-22 16:10:51 -0300 |
---|---|---|
committer | Bruno Oliveira <nicoddemus@gmail.com> | 2020-05-23 11:50:33 -0300 |
commit | 1780924b279a80aa3cccd840229dfe3e6f60e88b (patch) | |
tree | fd92a95f065b900ad5248116c5785fb409dcbe41 /src/_pytest/timing.py | |
parent | c98bc4cd3d687fe9b392d8eecd905627191d4f06 (diff) | |
download | pytest-1780924b279a80aa3cccd840229dfe3e6f60e88b.tar.gz |
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.
Diffstat (limited to 'src/_pytest/timing.py')
-rw-r--r-- | src/_pytest/timing.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/_pytest/timing.py b/src/_pytest/timing.py new file mode 100644 index 000000000..ded917b35 --- /dev/null +++ b/src/_pytest/timing.py @@ -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"] |