Skip to content

Commit 63aef2e

Browse files
committed
TEMPORARY commit: implement test for pytest-dev#90
This commit implements a test for pytest-dev#90 (logging customisation) that is wide-ranging as it (ab)uses all other tests in the suite to also check that the feature implemented in the above-mentioned pull request works. As the implications are currently not completely clear, this commit is marked as temporary and will either be discarded or merged into a previous commit in the pr before it is merged. The most important open question is: If a change breaks pytest-dev#90, will this be visible to the developers? The tests in the suite run other tests using the `tempdir` facility and this hacky implementation just adds a `conftest.py` to each of the temporary directories. Will the message from the assert message ever reach the output of the pytest-timeout test suite? Can that be somehow enforced from within the child-tests or their pytest runner?
1 parent 971817e commit 63aef2e

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

conftest.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
import pytest
3+
4+
5+
@pytest.hookimpl(hookwrapper=True)
6+
def pytest_runtest_call(item):
7+
"""Create a conftest.py file.
8+
9+
This should be considered a test, not a fixture!
10+
By creating a conftest.py file before actually running the test,
11+
it can be tested/ensured that the functionality implemented in
12+
#90 works reliably.
13+
With untypical test, all other tests are employed to ensure correct
14+
behaviour in terms of #90 apart from their designated checks.
15+
16+
The implementation is inspired by ``_pytest.python.pytest_pyfunc_call``:
17+
https://github.com/pytest-dev/pytest/blob/
18+
f28421cc7068b13ba63c1f60cc21f898cccea36c/src/_pytest/python.py#L179
19+
"""
20+
testdir = item.funcargs.get("testdir", None)
21+
if hasattr(testdir, "makepyfile"):
22+
testdir.makepyfile(
23+
conftest="""
24+
import pytest
25+
26+
@pytest.hookimpl(hookwrapper=True)
27+
def pytest_runtest_makereport(item, call):
28+
r = yield
29+
if not hasattr(r, "get_result"):
30+
return
31+
report = r.get_result()
32+
timed_out = False
33+
if hasattr(call.excinfo, "value"):
34+
msg = getattr(call.excinfo.value, "msg", None)
35+
if isinstance(msg, str) and msg.startswith("Timeout >"):
36+
timed_out = True
37+
ref_timed_out = bool(getattr(report, "timed_out", None))
38+
assert ref_timed_out == timed_out, "#90 customisation broken!"
39+
"""
40+
)
41+
yield

test_pytest_timeout.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -482,36 +482,3 @@ 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)