summaryrefslogtreecommitdiff
path: root/src/_pytest/pytester.py
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2020-05-22 16:10:51 -0300
committerBruno Oliveira <nicoddemus@gmail.com>2020-05-23 11:50:33 -0300
commit1780924b279a80aa3cccd840229dfe3e6f60e88b (patch)
treefd92a95f065b900ad5248116c5785fb409dcbe41 /src/_pytest/pytester.py
parentc98bc4cd3d687fe9b392d8eecd905627191d4f06 (diff)
downloadpytest-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/pytester.py')
-rw-r--r--src/_pytest/pytester.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py
index 32b03bd4a..07250b245 100644
--- a/src/_pytest/pytester.py
+++ b/src/_pytest/pytester.py
@@ -7,7 +7,6 @@ import platform
import re
import subprocess
import sys
-import time
import traceback
from fnmatch import fnmatch
from io import StringIO
@@ -24,6 +23,7 @@ from weakref import WeakKeyDictionary
import py
import pytest
+from _pytest import timing
from _pytest._code import Source
from _pytest.capture import MultiCapture
from _pytest.capture import SysCapture
@@ -941,7 +941,7 @@ class Testdir:
if syspathinsert:
self.syspathinsert()
- now = time.time()
+ now = timing.time()
capture = MultiCapture(Capture=SysCapture)
capture.start_capturing()
try:
@@ -970,7 +970,7 @@ class Testdir:
sys.stderr.write(err)
res = RunResult(
- reprec.ret, out.splitlines(), err.splitlines(), time.time() - now
+ reprec.ret, out.splitlines(), err.splitlines(), timing.time() - now
)
res.reprec = reprec # type: ignore
return res
@@ -1171,7 +1171,7 @@ class Testdir:
f1 = open(str(p1), "w", encoding="utf8")
f2 = open(str(p2), "w", encoding="utf8")
try:
- now = time.time()
+ now = timing.time()
popen = self.popen(
cmdargs,
stdin=stdin,
@@ -1218,7 +1218,7 @@ class Testdir:
ret = ExitCode(ret)
except ValueError:
pass
- return RunResult(ret, out, err, time.time() - now)
+ return RunResult(ret, out, err, timing.time() - now)
def _dump_lines(self, lines, fp):
try: