Fix: Handle pytest.exit() from workers gracefully#1347
Open
C1-BA-B1-F3 wants to merge 1 commit into
Open
Conversation
When pytest.exit() is called in a worker test, it raises pytest.exit.Exception (a BaseException subclass). Previously, the worker's runtest loop would exit without marking the current test as complete, causing the controller's scheduler to treat it as a crash. This fix: - Adds a pytest_keyboard_interrupt hook in WorkerInteractor to detect pytest.exit.Exception and store exit info in workeroutput - In DSession.worker_workerfinished, checks for the exit info and handles it gracefully without asserting crashitem - In pytest_runtestloop, re-raises pytest.exit.Exception to preserve the requested return code Fixes pytest-dev#1239
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
pytest.exit()on workers via thepytest_keyboard_interrupthookpytest.exit.Exceptionin the controller to preserve the requested return codeFixes #1239
Changes
src/xdist/remote.py (Worker side):
pytest_keyboard_interrupthook inWorkerInteractorto detectpytest.exit.Exceptionexitreasonandexitreturncodeinworkeroutputwhenpytest.exit()is calledsrc/xdist/dsession.py (Controller side):
_worker_exitfield to track worker exit viapytest.exit()worker_workerfinished, checks for exit info and handles gracefully (no crashitem assertion)pytest_runtestloop, re-raisespytest.exit.Exceptionto preserve return codetesting/acceptance_test.py:
pytest.exit()with return codes 0 and 1Tests
pytest testing/acceptance_test.py::TestNodeFailure::test_pytest_exit_is_not_reported_as_internal_error -v- PASSEDpytest testing/acceptance_test.py::TestNodeFailure -v- All existing tests PASSEDCloses #1239