Skip to content

Fix fixture display commands discarding non-zero exit statuses - #15048

Open
lpyu001 wants to merge 1 commit into
pytest-dev:mainfrom
lpyu001:fixture
Open

lpyu001 wants to merge 1 commit into
pytest-dev:mainfrom
lpyu001:fixture

Conversation

@lpyu001

@lpyu001 lpyu001 commented Sep 17, 2026

Copy link
Copy Markdown

Preserve the exit status returned by showfixtures() and show_fixtures_per_test() instead of unconditionally returning 0 from pytest_cmdline_main().

Collection errors require additional handling because Session.perform_collect() records them in session.testsfailed without raising. Extracted the existing collection-error check from pytest_runtestloop() into _raise_on_collection_errors() and reused it for the fixture display commands. With --continue-on-collection-errors, the commands now return ExitCode.TESTS_FAILED when collection errors occurred.

Added regression tests for both --fixtures and --fixtures-per-test. Pre-fix:

$ python -m pytest --fixtures test_bad.py
...
ERROR test_bad.py
=============================== 1 error in 0.09s ===============================
exit=0

After the fix, collection errors return ExitCode.INTERRUPTED (2), or ExitCode.TESTS_FAILED (1) with --continue-on-collection-errors. Exit statuses produced by internal errors and pytest.exit() are also preserved instead of being replaced with 0.

Closes #15047.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Sep 17, 2026
… errored

Preserve exit statuses returned by fixture display commands and handle
collection errors consistently with the main pytest execution path.

Co-authored-by: ChatGPT <noreply@openai.com>

@bluetech bluetech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I made some tweaks but it should be good for pytest 10.0.

@bluetech bluetech added this to the 10.0 milestone Sep 17, 2026
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.

--fixtures and --fixtures-per-test exit with code 0 on collection errors, internal errors and pytest.exit()

2 participants