Skip to content

Commit

Permalink
Avoid race conditions when running tests with xdist
Browse files Browse the repository at this point in the history
  • Loading branch information
hroncok committed Dec 13, 2022
1 parent f71dd2a commit 028ee0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import os
import shutil

import pytest
from utils import FIXTURES_DIR, TOX4


@pytest.fixture(autouse=True)
def projdir(tmp_path, monkeypatch):
def projdir(tmp_path, monkeypatch, worker_id):
pwd = tmp_path / "projdir"
pwd.mkdir()
for fname in "tox.ini", "setup.py":
shutil.copy(FIXTURES_DIR / fname, pwd)
monkeypatch.chdir(pwd)
# https://github.com/pypa/pip/issues/5345#issuecomment-386424455
monkeypatch.setenv("XDG_CACHE_HOME",
os.path.expanduser(f"~/.cache/pytest-xdist-{worker_id}"))
return pwd


Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
envlist = py36,py37,py38,py39,py310,py311

[testenv]
passenv =
XDG_CACHE_HOME
deps =
six
py
Expand Down

0 comments on commit 028ee0c

Please sign in to comment.