|
| 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 |
0 commit comments