Repository navigation
Conversation
`_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
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15378.
Problem
pytest --fixturescrashes with anINTERNALERROR(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 siblingconftest.pyfiles._showfixtures_mainbuilds sort tuples of(len(baseid), module, path, argname, fixturedef)and callslist.sort()on them. When the display columns tie, sorting falls through to comparing theFixtureDefobjects themselves, which do not define ordering.Change
Sort by the display columns only (
key=lambda item: item[:4]). TheFixtureDefis 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 toAUTHORS.Verification
Reproduced the crash on unpatched
mainwith a project where two sibling conftests import the same fixture from a shared module (pytest --fixtures->INTERNALERRORwith theTypeErrorabove); after the fix the same command exits 0 and lists the fixture.The new test fails on unpatched code with the same
TypeErrorand passes with the fix.testing/python/fixtures.py: 244 passed, 1 skipped, 2 xfailed.ruff checkandruff format --checkpass 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
changelogdirectory.Add yourself to
AUTHORSin 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.