Skip to content

Commit 02cb5ab

Browse files
committed
Attempt fix for failing tests
1 parent b5ec6ad commit 02cb5ab

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

tests/conftest.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,25 @@ def headless_environ(pytestconfig: pytest.Config):
4444
return False
4545

4646

47+
def get_lock_dir(tmp_path_factory, worker_id):
48+
if worker_id == "master":
49+
return tmp_path_factory.getbasetemp()
50+
return tmp_path_factory.getbasetemp().parent
51+
52+
4753
@pytest.fixture(autouse=True, scope="session")
48-
def install_playwright():
49-
subprocess.run(["playwright", "install", "chromium"], check=True) # noqa: S607
50-
# Try to install system deps, but don't fail if already installed or no root access
51-
with contextlib.suppress(subprocess.CalledProcessError):
52-
subprocess.run(["playwright", "install-deps"], check=True) # noqa: S607
54+
def install_playwright(tmp_path_factory, worker_id):
55+
root_tmp_dir = get_lock_dir(tmp_path_factory, worker_id)
56+
fn = root_tmp_dir / "playwright_install.lock"
57+
flag = root_tmp_dir / "playwright_install.done"
58+
59+
with FileLock(str(fn)):
60+
if not flag.exists():
61+
subprocess.run(["playwright", "install", "chromium"], check=True) # noqa: S607
62+
# Try to install system deps, but don't fail if already installed or no root access
63+
with contextlib.suppress(subprocess.CalledProcessError):
64+
subprocess.run(["playwright", "install-deps"], check=True) # noqa: S607
65+
flag.touch()
5366

5467

5568
@pytest.fixture(autouse=True, scope="session")
@@ -62,7 +75,7 @@ def rebuild(tmp_path_factory, worker_id):
6275
env = os.environ.copy()
6376
env.pop("HATCH_ENV_ACTIVE", None)
6477

65-
root_tmp_dir = tmp_path_factory.getbasetemp().parent
78+
root_tmp_dir = get_lock_dir(tmp_path_factory, worker_id)
6679
fn = root_tmp_dir / "build.lock"
6780
flag = root_tmp_dir / "build.done"
6881

0 commit comments

Comments
 (0)