Skip to content

Commit 2e96621

Browse files
authored
Change error message to clearly relate it to pytest-timeout (#180)
Closes #179
1 parent 733b26b commit 2e96621

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

pytest_timeout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
__all__ = ("is_debugging", "Settings")
2222
SESSION_TIMEOUT_KEY = pytest.StashKey[float]()
2323
SESSION_EXPIRE_KEY = pytest.StashKey[float]()
24-
24+
PYTEST_FAILURE_MESSAGE = "Timeout (>%ss) from pytest-timeout."
2525

2626
HAVE_SIGALRM = hasattr(signal, "SIGALRM")
2727
if HAVE_SIGALRM:
@@ -499,7 +499,7 @@ def timeout_sigalrm(item, settings):
499499
dump_stacks(terminal)
500500
if nthreads > 1:
501501
terminal.sep("+", title="Timeout")
502-
pytest.fail("Timeout >%ss" % settings.timeout)
502+
pytest.fail(PYTEST_FAILURE_MESSAGE % settings.timeout)
503503

504504

505505
def timeout_timer(item, settings):

test_pytest_timeout.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
import pexpect
77
import pytest
8+
from pytest_timeout import PYTEST_FAILURE_MESSAGE
89

10+
11+
MATCH_FAILURE_MESSAGE = f"*Failed: {PYTEST_FAILURE_MESSAGE}*"
912
pytest_plugins = "pytester"
1013

1114
have_sigalrm = pytest.mark.skipif(
@@ -44,7 +47,7 @@ def test_foo():
4447
"""
4548
)
4649
result = pytester.runpytest_subprocess("--timeout=1")
47-
result.stdout.fnmatch_lines(["*Failed: Timeout >1.0s*"])
50+
result.stdout.fnmatch_lines([MATCH_FAILURE_MESSAGE % "1.0"])
4851

4952

5053
def test_thread(pytester):
@@ -239,7 +242,7 @@ def test_foo():
239242
"""
240243
)
241244
result = pytester.runpytest_subprocess()
242-
result.stdout.fnmatch_lines(["*Failed: Timeout >1.0s*"])
245+
result.stdout.fnmatch_lines([MATCH_FAILURE_MESSAGE % "1.0"])
243246

244247

245248
def test_timeout_mark_timer(pytester):
@@ -480,7 +483,7 @@ def test_foo():
480483
result = child.read().decode().lower()
481484
if child.isalive():
482485
child.terminate(force=True)
483-
assert "timeout >1.0s" not in result
486+
assert "timeout (>1.0s)" not in result
484487
assert "fail" not in result
485488

486489

@@ -524,7 +527,7 @@ def test_foo():
524527
result = child.read().decode().lower()
525528
if child.isalive():
526529
child.terminate(force=True)
527-
assert "timeout >1.0s" in result
530+
assert "timeout (>1.0s)" in result
528531
assert "fail" in result
529532

530533

0 commit comments

Comments
 (0)