From e407a3377efc25630614202089d52a1de42e03df Mon Sep 17 00:00:00 2001 From: Aleksandr Mezin Date: Wed, 7 Sep 2022 02:37:38 +0600 Subject: [PATCH] Cancel shutdown when crashed worker is restarted (#813) Co-authored-by: Bruno Oliveira --- changelog/813.bugfix | 1 + src/xdist/dsession.py | 1 + testing/test_newhooks.py | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 changelog/813.bugfix diff --git a/changelog/813.bugfix b/changelog/813.bugfix new file mode 100644 index 0000000..251cf4b --- /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 2ae3db6..a950df6 100644 --- a/src/xdist/dsession.py +++ b/src/xdist/dsession.py @@ -225,6 +225,7 @@ class DSession: 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 012f1ea..dcd2bc0 100644 --- a/testing/test_newhooks.py +++ b/testing/test_newhooks.py @@ -94,3 +94,28 @@ class TestCrashItem: 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", + ] + )