From 030f0d5027e13cf2658d145170fe7166676ef7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 13 Apr 2023 11:36:42 +0200 Subject: [PATCH] Avoid race conditions in tests using the demo_pkg_inline fixture By using FileLock (already used as a dependency), we ensure only one test uses the demo_pkg at a time. This avoids race conditions happening with `pytest -n=auto`. Fixes https://github.com/tox-dev/tox/issues/2985 --- docs/changelog/2985.bugfix.rst | 1 + tests/conftest.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 docs/changelog/2985.bugfix.rst diff --git a/docs/changelog/2985.bugfix.rst b/docs/changelog/2985.bugfix.rst new file mode 100644 index 0000000000..da609dcba1 --- /dev/null +++ b/docs/changelog/2985.bugfix.rst @@ -0,0 +1 @@ +Avoid race conditions in tests using the ``demo_pkg_inline`` fixture. diff --git a/tests/conftest.py b/tests/conftest.py index b3086268d3..eaccae979f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,6 +11,7 @@ from _pytest.monkeypatch import MonkeyPatch # cannot import from tox.pytest yet from _pytest.tmpdir import TempPathFactory from distlib.scripts import ScriptMaker +from filelock import FileLock from pytest_mock import MockerFixture from virtualenv import cli_run @@ -77,8 +78,10 @@ def demo_pkg_setuptools() -> Path: @pytest.fixture(scope="session") -def demo_pkg_inline() -> Path: - return HERE / "demo_pkg_inline" +def demo_pkg_inline() -> Iterator[Path]: + demo_path = HERE / "demo_pkg_inline" + with FileLock(str(demo_path) + ".lock"): + yield demo_path @pytest.fixture()