Skip to content

Commit 971817e

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 971817e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test_pytest_timeout.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,36 @@ 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(
489+
conftest="""
490+
import pytest
491+
492+
@pytest.hookimpl(hookwrapper=True)
493+
def pytest_runtest_makereport(item, call):
494+
r = yield
495+
if not hasattr(r, "get_result"):
496+
return
497+
report = r.get_result()
498+
timed_out = False
499+
if hasattr(call.excinfo, "value"):
500+
msg = getattr(call.excinfo.value, "msg", None)
501+
if isinstance(msg, str) and msg.startswith("Timeout >"):
502+
timed_out = True
503+
assert bool(getattr(report, "timed_out", None)) == timed_out
504+
"""
505+
)
506+
testdir.makepyfile(
507+
"""
508+
import time
509+
510+
def test_times_out():
511+
time.sleep(2)
512+
513+
def test_does_not_time_out():
514+
time.sleep(0.1)
515+
"""
516+
)
517+
testdir.runpytest("--timeout=1", "-ss")

0 commit comments

Comments
 (0)