Skip to content

Commit

Permalink
Avoid race conditions in tests using the demo_pkg_inline fixture
Browse files Browse the repository at this point in the history
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 #2985
  • Loading branch information
hroncok committed Apr 13, 2023
1 parent ea169d0 commit 348788e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog/2985.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid race conditions in tests using the ``demo_pkg_inline`` fixture.
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -78,7 +79,9 @@ def demo_pkg_setuptools() -> Path:

@pytest.fixture(scope="session")
def demo_pkg_inline() -> Path:
return HERE / "demo_pkg_inline"
demo_path = HERE / "demo_pkg_inline"
with FileLock(str(demo_path) + ".lock"):
yield demo_path


@pytest.fixture()
Expand Down

0 comments on commit 348788e

Please sign in to comment.