fix: handle pytest.exit with non-zero exit codes properly#1320
Open
BlocksecPHD wants to merge 2 commits intopytest-dev:masterfrom
Open
fix: handle pytest.exit with non-zero exit codes properly#1320BlocksecPHD wants to merge 2 commits intopytest-dev:masterfrom
BlocksecPHD wants to merge 2 commits intopytest-dev:masterfrom
Conversation
added 2 commits
April 9, 2026 07:24
Issue pytest-dev#1239: pytest.exit() with non-zero exit code caused INTERNALERROR in xdist. The assertion 'assert not crashitem' failed because the scheduler had pending tests when the worker exited. Changes: - Handle non-zero exit statuses (other than 2) similarly to keyboard-interrupt - Worker exits with custom exit codes now trigger shouldstop and proper shutdown - Add test case to verify INTERNALERROR is not raised Note: The session exit status is INTERRUPTED (2) due to shouldstop handling, but the fix prevents INTERNALERROR which was the main issue.
The previous fix was too aggressive - handling all non-zero exitstatuses as pytest.exit cases. This broke normal test execution where exitstatus=1 means tests failed normally. The correct approach: check if crashitem is non-empty after removing the node. If there are pending tests when the worker exits, handle it gracefully instead of raising INTERNALERROR. This fixes issue pytest-dev#1239 without breaking normal test workflows.
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.
Summary
Fixes #1239
pytest.exit() with non-zero exit code caused INTERNALERROR in xdist. The assertion
assert not crashitemfailed because the scheduler had pending tests when the worker exited.Changes
worker_workerfinishedshouldstopand proper shutdownTesting
test_pytest_exit_nonzero_exitcodetest caseNote
The session exit status is INTERRUPTED (2) due to
shouldstophandling, but the fix prevents INTERNALERROR which was the main issue reported in #1239.