test(upgrade): make pip-flag tests hermetic, cover uv branch
uv run injects VIRTUAL_ENV, which silently selects the uv pip branch and broke test_uses_break_system_packages_on_externally_managed. Both tests now delete VIRTUAL_ENV to pin the plain-pip branch; new test pins the uv branch via mocks.
This commit is contained in:
@@ -238,6 +238,9 @@ class TestPipInstallFlags:
|
||||
) -> None:
|
||||
import sysconfig
|
||||
|
||||
# Force the plain-pip branch regardless of how pytest was launched
|
||||
# (e.g. `uv run` sets VIRTUAL_ENV, which would select the uv branch).
|
||||
monkeypatch.delenv("VIRTUAL_ENV", raising=False)
|
||||
em = tmp_path / "EXTERNALLY-MANAGED"
|
||||
em.write_text("[externally-managed]\n")
|
||||
monkeypatch.setattr(
|
||||
@@ -257,6 +260,7 @@ class TestPipInstallFlags:
|
||||
) -> None:
|
||||
import sysconfig
|
||||
|
||||
monkeypatch.delenv("VIRTUAL_ENV", raising=False)
|
||||
monkeypatch.setattr(
|
||||
sysconfig, "get_path", lambda name: str(tmp_path) if name == "stdlib" else ""
|
||||
)
|
||||
@@ -268,3 +272,18 @@ class TestPipInstallFlags:
|
||||
)
|
||||
up_mod._pip_install(tmp_path / "pkg")
|
||||
assert "--break-system-packages" not in seen[0]
|
||||
|
||||
def test_prefers_uv_pip_inside_virtualenv(
|
||||
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.setenv("VIRTUAL_ENV", str(tmp_path / "venv"))
|
||||
monkeypatch.setattr(up_mod.shutil, "which", lambda name: f"/usr/bin/{name}")
|
||||
seen: list[list[str]] = []
|
||||
monkeypatch.setattr(
|
||||
"subprocess.run",
|
||||
lambda cmd, **kw: seen.append(cmd)
|
||||
or type("R", (), {"returncode": 0, "stderr": ""})(),
|
||||
)
|
||||
up_mod._pip_install(tmp_path / "pkg")
|
||||
assert seen[0][:3] == ["uv", "pip", "install"]
|
||||
assert "--break-system-packages" not in seen[0]
|
||||
|
||||
Reference in New Issue
Block a user