From dcd635ba0cbba40efce1947071cc0cfb7830952e Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Thu, 4 Oct 2018 22:11:02 -0400 Subject: [PATCH] Correct timeout to check every so often --- src/_pytest/pytester.py | 4 +++- testing/test_pytester.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index d7ad6e3b0..73265f52b 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -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() diff --git a/testing/test_pytester.py b/testing/test_pytester.py index ebc699cc5..de5145250 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -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( """