|
7 | 7 | import textwrap
|
8 | 8 | from os.path import curdir, join, pardir
|
9 | 9 | from pathlib import Path
|
10 |
| -from typing import Dict, List, Tuple |
| 10 | +from typing import Callable, Dict, Iterable, List, Optional, Tuple |
11 | 11 |
|
12 | 12 | import pytest
|
13 | 13 |
|
|
20 | 20 | PipTestEnvironment,
|
21 | 21 | ResolverVariant,
|
22 | 22 | TestData,
|
| 23 | + TestPipResult, |
23 | 24 | _create_svn_repo,
|
24 | 25 | _create_test_package,
|
25 | 26 | create_basic_wheel_for_package,
|
@@ -2371,14 +2372,68 @@ def test_install_logs_pip_version_in_debug(
|
2371 | 2372 | assert_re_match(pattern, result.stdout)
|
2372 | 2373 |
|
2373 | 2374 |
|
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) |
2379 | 2422 | assert "Would install simple-3.0" in result.stdout
|
2380 | 2423 | assert "Successfully installed" not in result.stdout
|
2381 | 2424 |
|
| 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 | + |
2382 | 2437 |
|
2383 | 2438 | @pytest.mark.skipif(
|
2384 | 2439 | sys.version_info < (3, 11),
|
|
0 commit comments