From 26b8d24366a98dc980154fdbcfc44be360167bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E4=BA=8C=E6=9C=88=E4=BD=9C=E6=9B=B2=E5=AE=B6?= Date: Thu, 18 Jun 2026 18:15:34 +0800 Subject: [PATCH] fix: handle pytest.exit in remote worker to prevent internal error When pytest.exit() is called during remote execution, it was uncaught and caused an internal error. Now catches pytest.exit.Exit and forwards the return code. --- src/xdist/remote.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/xdist/remote.py b/src/xdist/remote.py index 409b90b0..4535fcf3 100644 --- a/src/xdist/remote.py +++ b/src/xdist/remote.py @@ -434,4 +434,7 @@ def setup_config(config: pytest.Config, basetemp: str | None) -> None: config.workerinput = workerinput # type: ignore[attr-defined] config.workeroutput = {} # type: ignore[attr-defined] interactor = WorkerInteractor(config, channel) # type: ignore[name-defined] - config.hook.pytest_cmdline_main(config=config) + try: + config.hook.pytest_cmdline_main(config=config) + except pytest.exit.Exit as e: + workeroutput["exitstatus"] = e.returncode