Skip to content

Commit b7c8dbb

Browse files
committed
Add an integration test for --installpkg + automatically provisioned env.
1 parent 7fdd156 commit b7c8dbb

File tree

1 file changed

+56
-9
lines changed

1 file changed

+56
-9
lines changed

tests/test_provision.py

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from contextlib import contextmanager
88
from pathlib import Path
99
from subprocess import check_call
10-
from typing import TYPE_CHECKING, Callable, Iterator
10+
from typing import TYPE_CHECKING, Callable, Iterator, Sequence
1111
from unittest import mock
1212
from zipfile import ZipFile
1313

@@ -16,6 +16,7 @@
1616
from packaging.requirements import Requirement
1717

1818
if TYPE_CHECKING:
19+
from build import DistributionType
1920
from devpi_process import Index, IndexServer
2021

2122
from tox.pytest import MonkeyPatch, TempPathFactory, ToxProjectCreator
@@ -102,22 +103,38 @@ def tox_wheels(tox_wheel: Path, tmp_path_factory: TempPathFactory) -> list[Path]
102103

103104

104105
@pytest.fixture(scope="session")
105-
def pypi_index_self(pypi_server: IndexServer, tox_wheels: list[Path], demo_pkg_inline_wheel: Path) -> Index:
106-
with elapsed("start devpi and create index"): # takes around 1s
106+
def local_pypi_indexes(
107+
pypi_server: IndexServer, tox_wheels: list[Path], demo_pkg_inline_wheel: Path
108+
) -> tuple[Index, Index]:
109+
with elapsed("start devpi and create indexes"): # takes around 1s
110+
pypi_server.create_index("mirror", "type=mirror", "mirror_url=https://pypi.org/simple/")
111+
mirrored_index = pypi_server.create_index("magic", f"bases={pypi_server.user}/mirror")
107112
self_index = pypi_server.create_index("self", "volatile=False")
108-
with elapsed("upload tox and its wheels to devpi"): # takes around 3.2s on build
113+
with elapsed("upload tox and its wheels to devpi"): # takes around 3.2s on # build
114+
mirrored_index.upload(*tox_wheels, demo_pkg_inline_wheel)
109115
self_index.upload(*tox_wheels, demo_pkg_inline_wheel)
110-
return self_index
116+
return mirrored_index, self_index
111117

112118

113-
@pytest.fixture
114-
def _pypi_index_self(pypi_index_self: Index, monkeypatch: MonkeyPatch) -> None:
115-
pypi_index_self.use()
116-
monkeypatch.setenv("PIP_INDEX_URL", pypi_index_self.url)
119+
def _use_pypi_index(pypi_index: Index, monkeypatch: MonkeyPatch) -> None:
120+
pypi_index.use()
121+
monkeypatch.setenv("PIP_INDEX_URL", pypi_index.url)
117122
monkeypatch.setenv("PIP_RETRIES", str(2))
118123
monkeypatch.setenv("PIP_TIMEOUT", str(5))
119124

120125

126+
@pytest.fixture
127+
def _pypi_index_mirrored(local_pypi_indexes: Index, monkeypatch: MonkeyPatch) -> None:
128+
pypi_index_mirrored, _ = local_pypi_indexes
129+
_use_pypi_index(pypi_index_mirrored, monkeypatch)
130+
131+
132+
@pytest.fixture
133+
def _pypi_index_self(local_pypi_indexes: Index, monkeypatch: MonkeyPatch) -> None:
134+
_, pypi_index_self = local_pypi_indexes
135+
_use_pypi_index(pypi_index_self, monkeypatch)
136+
137+
121138
def test_provision_requires_nok(tox_project: ToxProjectCreator) -> None:
122139
ini = "[tox]\nrequires = pkg-does-not-exist\n setuptools==1\nskipsdist=true\n"
123140
outcome = tox_project({"tox.ini": ini}).run("c", "-e", "py")
@@ -254,3 +271,33 @@ def test_provision_default_arguments_exists(tox_project: ToxProjectCreator, subc
254271
outcome = project.run(subcommand)
255272
for argument in ["result_json", "hash_seed", "discover", "list_dependencies"]:
256273
assert hasattr(outcome.state.conf.options, argument)
274+
275+
276+
@pytest.mark.integration
277+
@pytest.mark.usefixtures("_pypi_index_mirrored")
278+
def test_provision_install_pkg_pep517(
279+
tmp_path_factory: TempPathFactory,
280+
tox_project: ToxProjectCreator,
281+
pkg_builder: Callable[[Path, Path, Sequence[DistributionType], bool], Path],
282+
) -> None:
283+
example = tmp_path_factory.mktemp("example")
284+
skeleton = """
285+
[build-system]
286+
requires = ["setuptools"]
287+
build-backend = "setuptools.build_meta"
288+
[project]
289+
name = "skeleton"
290+
version = "0.1.1337"
291+
"""
292+
(example / "pyproject.toml").write_text(skeleton)
293+
sdist = pkg_builder(example / "dist", example, ["sdist"], False)
294+
295+
tox_ini = r"""
296+
[tox]
297+
requires = demo-pkg-inline
298+
[testenv]
299+
commands = python -c "print(42)"
300+
"""
301+
project = tox_project({"tox.ini": tox_ini}, base=example)
302+
result = project.run("r", "-e", "py", "--installpkg", str(sdist), "--notest")
303+
result.assert_success()

0 commit comments

Comments
 (0)