pytest-dev / pytest-dev/pytest

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

Open
#15,051 1 comment 0 reactions 1 assignee View on GitHub

@bluetech is already working on this.

Since Sep 17, 2026.

topic: fixtures type: bug
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

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

---------------------------------------------------------------------------------------- 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.