Skip to content

Commit 2e247dc

Browse files
authored
✅ test: raise timeout for tests hitting real PyPI (#4011)
1 parent 2c1f86f commit 2e247dc

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

tests/conftest.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import site
66
import sys
77
import sysconfig
8+
from functools import partial
89
from pathlib import Path
10+
from shutil import rmtree
11+
from tempfile import mkdtemp
912
from typing import TYPE_CHECKING, Protocol
1013
from unittest.mock import patch
1114
from uuid import uuid4
@@ -142,15 +145,17 @@ def get_python(self: VirtualEnv, base_python: list[str]) -> PythonInfo | None:
142145
return _func
143146

144147

145-
@pytest.fixture(scope="session", autouse=True)
146-
def _do_not_share_virtualenv_for_parallel_runs(tmp_path_factory: pytest.TempPathFactory, worker_id: str) -> None:
147-
# virtualenv uses locks to manage access to its cache, when running with xdist this may throw off test timings
148-
if worker_id != "master": # pragma: no branch
149-
temp_app_data = str(tmp_path_factory.mktemp(f"virtualenv-app-{worker_id}")) # pragma: no cover
150-
os.environ["VIRTUALENV_APP_DATA"] = temp_app_data # pragma: no cover
151-
seed_env_folder = str(tmp_path_factory.mktemp(f"seed-cache-{worker_id}")) # pragma: no cover
152-
args = [seed_env_folder, "--without-pip", "--activators", ""] # pragma: no cover
153-
cli_run(args, setup_logging=False) # pragma: no cover
148+
def pytest_configure(config: pytest.Config) -> None:
149+
if (worker_id := os.environ.get("PYTEST_XDIST_WORKER")) is not None: # pragma: no cover
150+
# virtualenv locks its app data, so sharing one across xdist workers throws off test timings
151+
app_data = mkdtemp(prefix=f"virtualenv-app-{worker_id}-")
152+
os.environ["VIRTUALENV_APP_DATA"] = app_data
153+
config.add_cleanup(partial(rmtree, app_data, ignore_errors=True))
154+
seed_env = mkdtemp(prefix="virtualenv-seed-")
155+
config.add_cleanup(partial(rmtree, seed_env, ignore_errors=True))
156+
# seeding builds the pip wheel image, a compileall over pip's tree that is slow on Windows CI; pay it here so it
157+
# does not land inside the timeout of whichever test happens to create the first environment
158+
cli_run([seed_env, "--activators", ""], setup_logging=False)
154159

155160

156161
@pytest.fixture(scope="session")

0 commit comments

Comments
 (0)