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