Skip to content

fixtures: --fixtures-per-test crashes on fixture-using doctest #15051

Description

@bluetech

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

topic: fixturesanything involving fixtures directly or indirectlytype: bugproblem that needs to be addressed

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions