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 293277e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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.
7 changes: 5 additions & 2 deletions 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 @@ -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(f"{demo_path}.lock"):
yield demo_path


@pytest.fixture()
Expand Down

0 comments on commit 293277e

Please sign in to comment.