Repository navigation
Stop cleanly when a worker interrupts the session after collection errors - #1439
megacodes24 wants to merge 2 commits into
Conversation
|
🤖 Written by Claude Opus 5.5 via Claude Code for the pytest-xdist maintainers; I prompted it, it did the work, I read it. Thanks for picking this up. I checked it against the pytest-dev/pytest#15384 branch: on master One problem is the overlap with #1438, which reworks the same exit paths for #1438 keeps these cases under one private # remote.py, in #1438's pytest_keyboard_interrupt
elif isinstance(excinfo.value, pytest.Session.Interrupted):
workeroutput = self.config.workeroutput
workeroutput[_TERMINAL_ERROR_KEY] = ("interrupted", str(excinfo.value))
# dsession.py, in _terminal_worker_error
if kind == "interrupted":
return Interrupted(payload)With that and your tests on top of #1438, the full suite passes with pytest 9.2 and with the pytest-dev/pytest#15384 branch. It also removes the node from the scheduler the same way the other terminal exits do. I'd like to land #1438 first and then rebase this onto it in that form. Does that work for you? Generated by Claude Code |
|
Thanks for checking it and for the trial merge, I hadn't noticed that #1438 adds the same hook. That works for me. I tried your suggestion on top of #1438 (the "interrupted" kind in pytest_keyboard_interrupt and _terminal_worker_error, plus my tests) and the tests pass with released pytest, pytest main and the pytest-dev/pytest#15384 branch. I'll keep this as a draft and rebase it onto #1438 in that form once it's merged. |
Companion to pytest-dev/pytest#15384, which moves the collection-error abort from
pytest_runtestlooptopytest_collection(pytest-dev/pytest#15028). With that change, each xdist worker raisesInterruptedafter collecting, exits with status 2, and the controller treats it as a keyboard interrupt: it keeps restarting workers until "maximum crashed workers reached", and a test that was already scheduled is reported as "worker crashed while running".Changes:
remote.py: the worker records the message inworkeroutput["interrupted"]frompytest_keyboard_interruptwhen the exception ispytest.Session.Interrupted(pytest_sessionfinishcan't see it, becausewrap_sessioncatches it without re-raising). A real Ctrl+C raises a plainKeyboardInterrupt, so it keeps the current behavior.dsession.py: inworker_workerfinished, an interrupted worker now stops the session cleanly (setsshouldstopto the worker's message, removes the node, triggers shutdown) instead of going throughworker_errordownand restarting.test_worker_collection_errors_abort(1 and 2 workers), which simulates the pytest change with a conftestpytest_collectionwrapper so it also runs with released pytest.test_n1_import_errorandtest_collection_crashnow accept exit code 1 orINTERRUPTED, andtest_n2_import_errorchecks the output based on the exit code. I first used apytest.version_tuple >= (10,)check, but pytest main already reports10.0.0.dev0without Move collection error abort from pytest_runtestloop to pytest_collection pytest#15384, so this way the tests pass whichever PR is merged first.Result with the pytest branch:
pytest -n2with an import error ends withxdist.dsession.Interrupted: 1 error during collection, with no restarts.Tested on Windows, Python 3.12: the full test suite passes with pytest 9.2.0 and with the pytest-dev/pytest#15384 branch. pre-commit passes.