Repository navigation
Handle terminal worker exits (pytest.exit, usage and internal errors) in one path - #1438
Draft
RonnyPfannschmidt wants to merge 6 commits into
Draft
RonnyPfannschmidt wants to merge 6 commits into
RonnyPfannschmidt wants to merge 6 commits into
Conversation
A worker that calls pytest.exit() used to leave pending tests behind, so the controller hit `assert not crashitem` and reported an INTERNALERROR. The worker now records the Exit reason and return code in pytest_keyboard_interrupt. The controller treats it like a worker usage error: it drops the worker's pending tests, shuts the other workers down and re-raises the original exception, so pytest reports it with the requested exit code. Approach follows #1346. Fixes #1239. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014GZsRDLMFm81zQ3iKPQusC
This was referenced Nov 27, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014GZsRDLMFm81zQ3iKPQusC
RonnyPfannschmidt
marked this pull request as draft
November 27, 2026 20:09
…output key
Both are stored as (kind, payload) under _TERMINAL_ERROR_KEY
("_xdist_terminal_error"), so they share one capture format and one
controller path and do not collide with keys plugins put in workeroutput.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014GZsRDLMFm81zQ3iKPQusC
…nfinish Since the switch to a new-style wrapper, an exception from another pytest_sessionfinish hook skipped the workerfinished event and the controller replaced the worker as crashed. Send it in a finally block, and record an Exit raised there, because pytest only applies it to the session's exit status after our hook ran. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014GZsRDLMFm81zQ3iKPQusC
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014GZsRDLMFm81zQ3iKPQusC
worker_internal_error no longer removes the node, so the later workerfinished/errordown no longer hits a KeyError (#986). A worker that finished with INTERNAL_ERROR now goes through the same terminal path as pytest.exit() and usage errors. The terminal error is raised from pytest_runtestloop after the remaining workers have shut down and reported back, instead of from worker_workerfinished. Tests and changelog for #986 come from #1384; the progress-line race in their output matching is fixed by matching with a leading wildcard. Co-authored-by: Leul Tewodros Agonafer <107800362+LeulTew@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014GZsRDLMFm81zQ3iKPQusC
This was referenced Nov 27, 2026
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.
Requested by Ronny · project thread
🤖 Written by Claude Opus 5.5 via Claude Code for the pytest-xdist maintainers; I prompted it, it did the work, I read it.
Fixes #1239 and #986: a worker ending the session via
pytest.exit(), a usage error or an internal error no longer crashes the controller (assert not crashitem/KeyError). Workers report usage errors and exits under one privateworkeroutputkey, the controller drops the worker's pending tests, shuts the others down and re-raises after they reported back, andworkerfinishedis now always sent even if anotherpytest_sessionfinishhook raises (a regression from thewrapper=Trueswitch in #1408). Supersedes #1320, #1342, #1346, #1347 and #1384; the #986 tests and changelog come from #1384 (co-authored).🤖 Generated with Claude Code
https://claude.ai/code/session_014GZsRDLMFm81zQ3iKPQusC