Skip to content

Commit 99aeda5

Browse files
committed
Add a test for logging customization.
This commit adds a simple test to verify that the `report.timed_out` attribute is set correctly.
1 parent 266f7a2 commit 99aeda5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test_pytest_timeout.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,34 @@ def custom_trace(*args):
482482
module.custom_trace = custom_trace
483483

484484
assert pytest_timeout.is_debugging(custom_trace)
485+
486+
487+
def test_logging_customization(testdir):
488+
testdir.makepyfile(conftest="""
489+
import pytest
490+
491+
@pytest.hookimpl(hookwrapper=True)
492+
def pytest_runtest_makereport(item, call):
493+
r = yield
494+
if not hasattr(r, "get_result"):
495+
return
496+
report = r.get_result()
497+
timed_out = False
498+
if hasattr(call.excinfo, "value"):
499+
msg = getattr(call.excinfo.value, "msg", None)
500+
if isinstance(msg, str) and msg.startswith("Timeout >"):
501+
timed_out = True
502+
assert bool(getattr(report, "timed_out", None)) == timed_out
503+
""")
504+
testdir.makepyfile(
505+
"""
506+
import time
507+
508+
def test_times_out():
509+
time.sleep(2)
510+
511+
def test_does_not_time_out():
512+
time.sleep(0.1)
513+
"""
514+
)
515+
testdir.runpytest("--timeout=1", "-ss")

0 commit comments

Comments
 (0)