Repository: pypa/pip
File: tests/functional/test_install.py (Python)

Code before:
            data.find_links,
            *args,
        )

    return install


@pytest.mark.parametrize(
    "with_target_dir",
    (True, False),
)
def test_install_dry_run_nothing_installed(
    script: PipTestEnvironment,
    tmpdir: Path,
    install_find_links: Callable[[Iterable[str], bool, Optional[Path]], TestPipResult],
    with_target_dir: bool,
) -> None:
    """Test that pip install --dry-run logs what it would install, but doesn't actually
    install anything."""
    if with_target_dir:
        install_dir = tmpdir / "fake-install"
        install_dir.mkdir()
    else:
        install_dir = None

    result = install_find_links(["simple"], True, install_dir)
    assert "Would install simple-3.0" in result.stdout
    assert "Successfully installed" not in result.stdout

    script.assert_not_installed("simple")
    if with_target_dir:
        assert not os.listdir(install_dir)

    # Ensure that the same install command would normally have worked if not for
    # --dry-run.
    install_find_links(["simple"], False, install_dir)
    if with_target_dir:
        assert os.listdir(install_dir)
    else:
        script.assert_installed(simple="3.0")


@pytest.mark.skipif(
    sys.version_info < (3, 11),
    reason="3.11 required to find distributions via importlib metadata",
)
def test_install_existing_memory_distribution(script: PipTestEnvironment) -> None:
    sitecustomize_text = textwrap.dedent(
        """
        import sys
        from importlib.metadata import Distribution, DistributionFinder

Review comment (suggestion):
Not particularly relevant since this is a test but it’d probably more readable to do something like `target=install_dir` to make it clearer it’s doing a `--target` install.

Code after:
        data.find_links,
        *args,
    )


@pytest.mark.parametrize(
    "with_target_dir",
    (True, False),
)
def test_install_dry_run_nothing_installed(
    script: PipTestEnvironment,
    data: TestData,
    tmpdir: Path,
    with_target_dir: bool,
) -> None:
    """Test that pip install --dry-run logs what it would install, but doesn't actually
    install anything."""
    if with_target_dir:
        install_dir = tmpdir / "fake-install"
        install_dir.mkdir()
    else:
        install_dir = None

    result = install_find_links(
        script, data, ["simple"], dry_run=True, target_dir=install_dir
    )
    assert "Would install simple-3.0" in result.stdout
    assert "Successfully installed" not in result.stdout

    script.assert_not_installed("simple")
    if with_target_dir:
        assert not os.listdir(install_dir)

    # Ensure that the same install command would normally have worked if not for
    # --dry-run.
    install_find_links(script, data, ["simple"], dry_run=False, target_dir=install_dir)
    if with_target_dir:
        assert os.listdir(install_dir)
    else:
        script.assert_installed(simple="3.0")


@pytest.mark.skipif(
    sys.version_info < (3, 11),
    reason="3.11 required to find distributions via importlib metadata",
)
def test_install_existing_memory_distribution(script: PipTestEnvironment) -> None:
    sitecustomize_text = textwrap.dedent(
        """
        import sys
        from importlib.metadata import Distribution, DistributionFinder