Skip to content

Commit 54400c8

Browse files
authored
tests: remove pytest-virtualenv (#125)
This is causing various problems, so remove it. Signed-off-by: Henry Schreiner <[email protected]>
1 parent 5c52d75 commit 54400c8

File tree

3 files changed

+67
-20
lines changed

3 files changed

+67
-20
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
run: python3.9 -m pip install .[test]
9191

9292
- name: Test package
93-
run: python3.9 -m pytest -ra --showlocals
93+
run: python3.9 -m pytest -ra --showlocals -m "not virtualenv"
9494

9595
msys:
9696
name: Tests on 🐍 3 • msys
@@ -148,7 +148,9 @@ jobs:
148148
run: python -m pip install .[test]
149149

150150
- name: Test package
151-
run: python -m pytest -ra --showlocals -k "not test_setuptools_pep518"
151+
run: python -m pytest -ra --showlocals -m "not setuptools"
152+
env:
153+
SETUPTOOLS_USE_DISTUTILS: "local"
152154

153155
dist:
154156
name: Distribution build

pyproject.toml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ dynamic = ["version"]
3333

3434
dependencies = [
3535
"exceptiongroup; python_version<'3.11'",
36-
"importlib_resources; python_version<'3.9'",
37-
"packaging", # TODO: set a min version
38-
"tomli; python_version<'3.11'",
36+
"importlib_resources>=1.3; python_version<'3.9'",
37+
"packaging>=20.9",
38+
"tomli>=1.1; python_version<'3.11'",
3939
"typing_extensions >=3.7; python_version<'3.8'",
4040
]
4141
# Note: for building wheels and sdists, there are also additional dependencies
@@ -44,24 +44,23 @@ dependencies = [
4444

4545
[project.optional-dependencies]
4646
pyproject = [
47-
"pyproject_metadata",
48-
"distlib",
49-
"pathspec",
47+
"pyproject-metadata>=0.5",
48+
"distlib>=0.3.5",
49+
"pathspec>=0.10.1",
5050
]
5151
rich = [
5252
"rich",
5353
]
5454
test = [
55-
"build",
55+
"build[virtualenv]",
5656
"cattrs >=22.2.0",
57-
"distlib",
57+
"distlib>=0.3.5",
5858
"importlib_metadata; python_version<'3.8'",
59-
"pathspec",
59+
"pathspec>=0.10.1",
6060
"pybind11",
61-
"pyproject-metadata",
61+
"pyproject-metadata>=0.5",
6262
"pytest >=7.2",
6363
"pytest-subprocess",
64-
"pytest-virtualenv",
6564
"rich",
6665
"setuptools",
6766
"wheel",
@@ -74,7 +73,6 @@ dev = [
7473
"cattrs >=22.2.0",
7574
"pytest >=7.2",
7675
"pytest-subprocess",
77-
"pytest-virtualenv",
7876
"rich",
7977
]
8078
docs = [

tests/conftest.py

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
from __future__ import annotations
22

3-
import importlib.util
3+
import os
4+
import shutil
45
import subprocess
56
import sys
7+
import types
8+
import warnings
9+
from collections.abc import Generator
610
from pathlib import Path
11+
from venv import EnvBuilder
712

813
if sys.version_info < (3, 8):
914
import importlib_metadata as metadata
@@ -63,13 +68,55 @@ def isolated(pep518_wheelhouse: str, monkeypatch: pytest.MonkeyPatch) -> None:
6368
monkeypatch.setenv("PIP_NO_INDEX", "true")
6469

6570

66-
has_pyvenv = importlib.util.find_spec("pytest_virtualenv") is not None
71+
class VEnv(EnvBuilder):
72+
executable: Path
73+
env_dir: Path
74+
75+
def __init__(self, env_dir: str) -> None:
76+
super().__init__(with_pip=True)
77+
# This warning is mistakenly generated by CPython 3.11.0
78+
# https://github.com/python/cpython/pull/98743
79+
with warnings.catch_warnings():
80+
if sys.version_info[:3] == (3, 11, 0):
81+
warnings.filterwarnings(
82+
"ignore",
83+
"check_home argument is deprecated and ignored.",
84+
DeprecationWarning,
85+
)
86+
self.create(env_dir)
87+
88+
def ensure_directories(
89+
self, env_dir: str | bytes | os.PathLike[str] | os.PathLike[bytes]
90+
) -> types.SimpleNamespace:
91+
context = super().ensure_directories(env_dir)
92+
# Store the path to the venv Python interpreter.
93+
# See https://github.com/mesonbuild/meson-python/blob/8a180be7b4abd7e1939a63d5d59f63197ee27cc7/tests/conftest.py#LL79
94+
self.executable = Path(context.env_exe)
95+
self.env_dir = Path(context.env_dir)
96+
return context
97+
98+
def run(self, expression: str, *, capture: bool = True) -> str:
99+
assert capture, "Always capture for now"
100+
env = os.environ.copy()
101+
env["PATH"] = f"{self.executable.parent}{os.pathsep}{env['PATH']}"
102+
env["VIRTUAL_ENV"] = str(self.env_dir)
103+
return subprocess.run(
104+
expression,
105+
check=True,
106+
capture_output=capture,
107+
text=True,
108+
shell=True,
109+
env=env,
110+
).stdout.strip()
67111

68-
if not has_pyvenv:
69112

70-
@pytest.fixture
71-
def virtualenv() -> None:
72-
pytest.skip("pytest-virtualenv not available")
113+
@pytest.fixture
114+
def virtualenv(tmp_path: Path) -> Generator[VEnv, None, None]:
115+
path = tmp_path / "venv"
116+
try:
117+
yield VEnv(str(path))
118+
finally:
119+
shutil.rmtree(path)
73120

74121

75122
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:

0 commit comments

Comments
 (0)