Skip to content

fix: sort --fixtures output by display columns only - #15414

Open
LiHuan02 wants to merge 1 commit into
pytest-dev:mainfrom
LiHuan02:fix-showfixtures-sort-crash
Open

LiHuan02 wants to merge 1 commit into
pytest-dev:mainfrom
LiHuan02:fix-showfixtures-sort-crash

Conversation

@LiHuan02

Copy link
Copy Markdown

Fixes #15378.

Problem

pytest --fixtures crashes with an INTERNALERROR (TypeError: '<' not supported between instances of 'FixtureDef' and 'FixtureDef') when the same fixture function is registered under two nodes -- for example, a fixture defined in a shared module and imported by two sibling conftest.py files.

_showfixtures_main builds sort tuples of (len(baseid), module, path, argname, fixturedef) and calls list.sort() on them. When the display columns tie, sorting falls through to comparing the FixtureDef objects themselves, which do not define ordering.

Change

Sort by the display columns only (key=lambda item: item[:4]). The FixtureDef is still carried in the tuple for display, but it is never compared.

Also added a regression test (test_show_fixtures_same_fixture_registered_twice), a changelog entry, and the author to AUTHORS.

Verification

  • Reproduced the crash on unpatched main with a project where two sibling conftests import the same fixture from a shared module (pytest --fixtures -> INTERNALERROR with the TypeError above); after the fix the same command exits 0 and lists the fixture.

  • The new test fails on unpatched code with the same TypeError and passes with the fix.

  • testing/python/fixtures.py: 244 passed, 1 skipped, 2 xfailed.

  • ruff check and ruff format --check pass on the changed files.

  • Include new tests or update existing tests when applicable.

  • Allow maintainers to push and squash when merging my commits.

  • Create a new changelog file in the changelog directory.

  • Add yourself to AUTHORS in alphabetical order.

AI assistance disclosure: this change was produced with the help of an AI coding assistant (Muse Spark); the author reviewed, verified, and takes responsibility for it.

`_showfixtures_main` built sort tuples that end with the FixtureDef
itself, which is not orderable. When the display columns tie -- for
example the same fixture function registered under two nodes --
`list.sort()` compared two FixtureDefs and raised
`TypeError: '<' not supported between instances of 'FixtureDef'
and 'FixtureDef'`, crashing `pytest --fixtures` with an
INTERNALERROR. Sort by the first four (display) columns instead.

Fixes pytest-dev#15378

Assisted-by: Muse Spark
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 18, 2026

This branch has not been deployed

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

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError when using --fixtures

1 participant