diff --git a/changelog/813.bugfix b/changelog/813.bugfix new file mode 100644 index 00000000..251cf4b9 --- /dev/null +++ b/changelog/813.bugfix @@ -0,0 +1 @@ +Cancel shutdown when a crashed worker is restarted. diff --git a/src/xdist/dsession.py b/src/xdist/dsession.py index 2ae3db6b..a950df62 100644 --- a/src/xdist/dsession.py +++ b/src/xdist/dsession.py @@ -225,6 +225,7 @@ def worker_errordown(self, node, error): self.triggershutdown() else: self.report_line("\nreplacing crashed worker %s" % node.gateway.id) + self.shuttingdown = False self._clone_node(node) self._active_nodes.remove(node) diff --git a/testing/test_newhooks.py b/testing/test_newhooks.py index 012f1ea7..dcd2bc05 100644 --- a/testing/test_newhooks.py +++ b/testing/test_newhooks.py @@ -94,3 +94,28 @@ def pytest_handlecrashitem(crashitem, report, sched): res = pytester.runpytest("-n2", "-s") res.stdout.fnmatch_lines_random(["*HOOK: pytest_handlecrashitem"]) res.stdout.fnmatch_lines(["*3 passed*"]) + + def test_handlecrashitem_one(self, pytester: pytest.Pytester) -> None: + """Test pytest_handlecrashitem hook with just one test.""" + pytester.makeconftest( + """ + test_runs = 0 + + def pytest_handlecrashitem(crashitem, report, sched): + global test_runs + + if test_runs == 0: + sched.mark_test_pending(crashitem) + test_runs = 1 + else: + print("HOOK: pytest_handlecrashitem") + """ + ) + res = pytester.runpytest("-n1", "-s", "-k", "test_b") + res.stdout.fnmatch_lines_random(["*HOOK: pytest_handlecrashitem"]) + res.stdout.fnmatch_lines( + [ + "FAILED test_handlecrashitem_one.py::test_b", + "FAILED test_handlecrashitem_one.py::test_b", + ] + )