From 04b5f5080210bd8d754b9bdea192c5f17bb6519c Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Fri, 3 Jul 2026 12:24:20 +1000 Subject: [PATCH] Isolate mypy cache per pytest-xdist worker --- pytest_mypy_plugins/item.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pytest_mypy_plugins/item.py b/pytest_mypy_plugins/item.py index f5af498..2e2bff7 100644 --- a/pytest_mypy_plugins/item.py +++ b/pytest_mypy_plugins/item.py @@ -365,6 +365,11 @@ def __init__( self.base_pyproject_toml_fpath = None self.incremental_cache_dir = os.path.join(self.root_directory, ".mypy_cache") + # The mypy cache is not safe for concurrent use; + # give each `pytest-xdist` worker its own cache directory. + if xdist_worker := os.environ.get("PYTEST_XDIST_WORKER"): + self.incremental_cache_dir = os.path.join(self.incremental_cache_dir, xdist_worker) + def remove_cache_files(self, fpath_no_suffix: Path) -> None: cache_dir = os.path.join( self.incremental_cache_dir,