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/runner.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/runner.py')
-rw-r--r-- | src/_pytest/runner.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index e7211369c..aa8a5aa8b 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -2,8 +2,6 @@ import bdb import os import sys -from time import perf_counter # Intentionally not `import time` to avoid being -from time import time # affected by tests which monkeypatch `time` (issue #185). from typing import Callable from typing import Dict from typing import List @@ -15,6 +13,7 @@ import attr from .reports import CollectErrorRepr from .reports import CollectReport from .reports import TestReport +from _pytest import timing from _pytest._code.code import ExceptionChainRepr from _pytest._code.code import ExceptionInfo from _pytest.compat import TYPE_CHECKING @@ -254,8 +253,8 @@ class CallInfo: #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" excinfo = None - start = time() - precise_start = perf_counter() + start = timing.time() + precise_start = timing.perf_counter() try: result = func() except BaseException: @@ -264,9 +263,9 @@ class CallInfo: raise result = None # use the perf counter - precise_stop = perf_counter() + precise_stop = timing.perf_counter() duration = precise_stop - precise_start - stop = time() + stop = timing.time() return cls( start=start, stop=stop, |