Skip to content

Commit 2619ea4

Browse files
committed
conftest(fix): Filter doctests at collection for control engine
Filter doctests from collection instead of skipping them to avoid pytest's _use_item_location bug: DoctestItem.reportinfo() returns None lineno for fixture doctests, which triggers assertion failure in _pytest/reports.py:420 when skipped via fixtures or markers. Both pytest.skip() in fixtures and pytest.mark.skip() trigger the same code path where pytest sets _use_item_location=True, causing the assertion to fail when it tries to use the item's location. The workaround removes doctests from the collected items list when running with --engine=control, avoiding the bug entirely.
1 parent 0291044 commit 2619ea4

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

conftest.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ def add_doctest_fixtures(
4040
) -> None:
4141
"""Configure doctest fixtures for pytest-doctest."""
4242
if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"):
43-
# Skip doctests for control mode: attach_to fixture lifecycle
44-
# doesn't survive doctests that kill sessions/servers.
45-
# TODO: Investigate proper fix for control mode doctest support.
46-
engine_opt = request.config.getoption("--engine", default="subprocess")
47-
if engine_opt == "control":
48-
pytest.skip("doctests not supported with --engine=control")
49-
5043
request.getfixturevalue("set_home")
5144
doctest_namespace["Server"] = Server
5245
doctest_namespace["Session"] = Session
@@ -205,3 +198,21 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
205198
else:
206199
params = [metafunc.config.getoption("--engine")]
207200
metafunc.parametrize("engine_name", params, indirect=True)
201+
202+
203+
def pytest_collection_modifyitems(
204+
config: pytest.Config,
205+
items: list[pytest.Item],
206+
) -> None:
207+
"""Filter out doctests when running with control engine.
208+
209+
Remove doctests from collection to avoid pytest's _use_item_location
210+
bug: DoctestItem.reportinfo() returns None lineno for fixture doctests,
211+
which triggers assertion failure in _pytest/reports.py:420 when skipped.
212+
"""
213+
engine_opt = config.getoption("--engine", default="subprocess")
214+
if engine_opt != "control":
215+
return
216+
217+
# Filter out DoctestItems - can't use skip markers due to pytest bug
218+
items[:] = [item for item in items if not isinstance(item, DoctestItem)]

0 commit comments

Comments
 (0)