From ba509f0addd85f2014f9768e5183ff3e82d3d009 Mon Sep 17 00:00:00 2001 From: Saravanan Padmanaban Date: Mon, 9 Jan 2023 21:40:05 +0000 Subject: [PATCH] Changelog updated to document PR #10641 --- changelog/10641.bugfix.rst | 1 + src/_pytest/stepwise.py | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 changelog/10641.bugfix.rst diff --git a/changelog/10641.bugfix.rst b/changelog/10641.bugfix.rst new file mode 100644 index 000000000..febaf5f4b --- /dev/null +++ b/changelog/10641.bugfix.rst @@ -0,0 +1 @@ +Fix a race condition when creating or updating the stepwise plugin's cache, which could occur when multiple xdist worker nodes try to simultaneously update the stepwise plugin's cache. \ No newline at end of file diff --git a/src/_pytest/stepwise.py b/src/_pytest/stepwise.py index cd2611692..74ad9dbd4 100644 --- a/src/_pytest/stepwise.py +++ b/src/_pytest/stepwise.py @@ -49,6 +49,8 @@ def pytest_sessionfinish(session: Session) -> None: if not session.config.getoption("stepwise"): assert session.config.cache is not None if hasattr(session.config, "workerinput"): + # Do not update cache if this process is a xdist worker to prevent + # race conditions (#10641). return # Clear the list of failing tests if the plugin is not active. session.config.cache.set(STEPWISE_CACHE_DIR, []) @@ -122,5 +124,7 @@ class StepwisePlugin: def pytest_sessionfinish(self) -> None: if hasattr(self.config, "workerinput"): + # Do not update cache if this process is a xdist worker to prevent + # race conditions (#10641). return self.cache.set(STEPWISE_CACHE_DIR, self.lastfailed)