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 7c6d21f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 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.
9 changes: 6 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import os
import sys
from pathlib import Path
from typing import Callable, Iterator, Sequence
from typing import Callable, Generator, Iterator, Sequence
from unittest.mock import patch
from uuid import uuid4

import pytest
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() -> Generator[Path, None, None]:
demo_path = HERE / "demo_pkg_inline"
with FileLock(str(demo_path) + ".lock"):
yield demo_path


@pytest.fixture()
Expand Down

0 comments on commit 7c6d21f

Please sign in to comment.