Correct timeout to check every so often
This commit is contained in:
parent
33f0338eeb
commit
dcd635ba0c
|
@ -1086,6 +1086,8 @@ class Testdir(object):
|
|||
else:
|
||||
end = time.time() + timeout
|
||||
|
||||
resolution = min(0.1, timeout / 10)
|
||||
|
||||
while True:
|
||||
ret = popen.poll()
|
||||
if ret is not None:
|
||||
|
@ -1095,7 +1097,7 @@ class Testdir(object):
|
|||
if remaining <= 0:
|
||||
handle_timeout()
|
||||
|
||||
time.sleep(remaining * 0.9)
|
||||
time.sleep(resolution)
|
||||
finally:
|
||||
f1.close()
|
||||
f2.close()
|
||||
|
|
|
@ -4,6 +4,7 @@ import os
|
|||
import py.path
|
||||
import pytest
|
||||
import sys
|
||||
import time
|
||||
import _pytest.pytester as pytester
|
||||
from _pytest.pytester import HookRecorder
|
||||
from _pytest.pytester import CwdSnapshot, SysModulesSnapshot, SysPathsSnapshot
|
||||
|
@ -408,6 +409,18 @@ def test_testdir_run_no_timeout(testdir):
|
|||
assert testdir.runpytest_subprocess(testfile).ret == EXIT_OK
|
||||
|
||||
|
||||
def test_testdir_run_with_timeout(testdir):
|
||||
testfile = testdir.makepyfile("def test_no_timeout(): pass")
|
||||
|
||||
start = time.time()
|
||||
result = testdir.runpytest_subprocess(testfile, timeout=10)
|
||||
end = time.time()
|
||||
duration = end - start
|
||||
|
||||
assert result.ret == EXIT_OK
|
||||
assert duration < 1
|
||||
|
||||
|
||||
def test_testdir_run_timeout_expires(testdir):
|
||||
testfile = testdir.makepyfile(
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue