Skip to content

Commit 8e305f2

Browse files
add test for the *existing* install --dry-run functionality
1 parent 5378a6e commit 8e305f2

File tree

1 file changed

+61
-6
lines changed

1 file changed

+61
-6
lines changed

tests/functional/test_install.py

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import textwrap
88
from os.path import curdir, join, pardir
99
from pathlib import Path
10-
from typing import Dict, List, Tuple
10+
from typing import Callable, Dict, Iterable, List, Optional, Tuple
1111

1212
import pytest
1313

@@ -20,6 +20,7 @@
2020
PipTestEnvironment,
2121
ResolverVariant,
2222
TestData,
23+
TestPipResult,
2324
_create_svn_repo,
2425
_create_test_package,
2526
create_basic_wheel_for_package,
@@ -2371,14 +2372,68 @@ def test_install_logs_pip_version_in_debug(
23712372
assert_re_match(pattern, result.stdout)
23722373

23732374

2374-
def test_install_dry_run(script: PipTestEnvironment, data: TestData) -> None:
2375-
"""Test that pip install --dry-run logs what it would install."""
2376-
result = script.pip(
2377-
"install", "--dry-run", "--find-links", data.find_links, "simple"
2378-
)
2375+
@pytest.fixture
2376+
def install_find_links(
2377+
script: PipTestEnvironment,
2378+
data: TestData,
2379+
) -> Callable[[Iterable[str], bool, Optional[Path]], TestPipResult]:
2380+
def install(
2381+
args: Iterable[str], dry_run: bool, target_dir: Optional[Path]
2382+
) -> TestPipResult:
2383+
return script.pip(
2384+
"install",
2385+
*(
2386+
(
2387+
"--target",
2388+
str(target_dir),
2389+
)
2390+
if target_dir is not None
2391+
else ()
2392+
),
2393+
*(("--dry-run",) if dry_run else ()),
2394+
"--no-index",
2395+
"--find-links",
2396+
data.find_links,
2397+
*args,
2398+
)
2399+
2400+
return install
2401+
2402+
2403+
@pytest.mark.parametrize(
2404+
"with_target_dir",
2405+
(True, False),
2406+
)
2407+
def test_install_dry_run_nothing_installed(
2408+
script: PipTestEnvironment,
2409+
tmpdir: Path,
2410+
install_find_links: Callable[[Iterable[str], bool, Optional[Path]], TestPipResult],
2411+
with_target_dir: bool,
2412+
) -> None:
2413+
"""Test that pip install --dry-run logs what it would install, but doesn't actually
2414+
install anything."""
2415+
if with_target_dir:
2416+
install_dir = tmpdir / "fake-install"
2417+
install_dir.mkdir()
2418+
else:
2419+
install_dir = None
2420+
2421+
result = install_find_links(["simple"], True, install_dir)
23792422
assert "Would install simple-3.0" in result.stdout
23802423
assert "Successfully installed" not in result.stdout
23812424

2425+
script.assert_not_installed("simple")
2426+
if with_target_dir:
2427+
assert not os.listdir(install_dir)
2428+
2429+
# Ensure that the same install command would normally have worked if not for
2430+
# --dry-run.
2431+
install_find_links(["simple"], False, install_dir)
2432+
if with_target_dir:
2433+
assert os.listdir(install_dir)
2434+
else:
2435+
script.assert_installed(simple="3.0")
2436+
23822437

23832438
@pytest.mark.skipif(
23842439
sys.version_info < (3, 11),

0 commit comments

Comments
 (0)