#15051·pytest

fixtures: `--fixtures-per-test` crashes on fixture-using doctest

Author: bluetechCreated Sep 17, 2026Updated Sep 17, 2026
Labelstype: bugtopic: fixtures

Running --fixtures-per-test on pytest's own test suite crashes with:

python
---------------------------------------------------------------------------------------- fixtures used by test_doctest.txt -----------------------------------------------------------------------------------------
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/ran/src/pytest/src/_pytest/main.py", line 333, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>                          ~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/ran/src/pytest/src/_pytest/fixtures.py", line 2497, in _show_fixtures_per_test
INTERNALERROR>     write_item(session_item)
INTERNALERROR>     ~~~~~~~~~~^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/ran/src/pytest/src/_pytest/fixtures.py", line 2491, in write_item
INTERNALERROR>     tw.sep("-", f"({get_best_relpath(item.function)})")  # type: ignore[attr-defined]
INTERNALERROR>                                      ^^^^^^^^^^^^^
INTERNALERROR> AttributeError: 'DoctestItem' object has no attribute 'function'

Doctests can use fixtures, but they don't have item.function, as the type ignore on the line correctly indicates.