Skip to content

Handle terminal worker exits (pytest.exit, usage and internal errors) in one path - #1438

Draft
RonnyPfannschmidt wants to merge 6 commits into
masterfrom
claude/project-thread-m2pdpu
Draft

RonnyPfannschmidt wants to merge 6 commits into
masterfrom
claude/project-thread-m2pdpu

Conversation

@RonnyPfannschmidt

@RonnyPfannschmidt RonnyPfannschmidt commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

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 private workeroutput key, the controller drops the worker's pending tests, shuts the others down and re-raises after they reported back, and workerfinished is now always sent even if another pytest_sessionfinish hook raises (a regression from the wrapper=True switch 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

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
@RonnyPfannschmidt
RonnyPfannschmidt marked this pull request as draft November 27, 2026 20:09
claude and others added 4 commits 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
@RonnyPfannschmidt RonnyPfannschmidt changed the title Handle pytest.exit() raised on workers Handle terminal worker exits (pytest.exit, usage and internal errors) in one path Nov 27, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pytest.exit causes internal error

2 participants