|
10 | 10 | from helpers import app_name, run_pipx_cli, skip_if_windows, unwrap_log_text |
11 | 11 | from package_info import PKG |
12 | 12 | from pipx import paths, shared_libs |
| 13 | +from pipx.util import PipxError |
| 14 | +from pipx.venv import Venv |
13 | 15 |
|
14 | 16 | TEST_DATA_PATH = "./testdata/test_package_specifier" |
15 | 17 |
|
@@ -263,7 +265,33 @@ def test_pip_args_forwarded_to_package_name_determination(pipx_temp_env, capsys) |
263 | 265 | ] |
264 | 266 | ) |
265 | 267 | captured = capsys.readouterr() |
266 | | - assert "Cannot determine package name from spec" in captured.err |
| 268 | + assert "--asdf" in captured.err |
| 269 | + assert "Cannot determine package name from spec" not in captured.err |
| 270 | + |
| 271 | + |
| 272 | +def test_package_name_determination_preserves_install_error(monkeypatch): |
| 273 | + class FailingBackend: |
| 274 | + def install(self, **kwargs): |
| 275 | + return subprocess.CompletedProcess( |
| 276 | + ["pip", "install", "requires-newer-python"], |
| 277 | + 1, |
| 278 | + stdout="", |
| 279 | + stderr="ERROR: Package 'requires-newer-python' requires a different Python\n", |
| 280 | + ) |
| 281 | + |
| 282 | + def no_installed_packages(): |
| 283 | + return set() |
| 284 | + |
| 285 | + venv = Venv(Path("requires-newer-python-venv")) |
| 286 | + monkeypatch.setattr(venv, "_backend", FailingBackend()) |
| 287 | + monkeypatch.setattr(venv, "list_installed_packages", no_installed_packages) |
| 288 | + |
| 289 | + with pytest.raises(PipxError) as excinfo: |
| 290 | + venv.install_package_no_deps("requires-newer-python", []) |
| 291 | + |
| 292 | + error = str(excinfo.value) |
| 293 | + assert "requires a different Python" in error |
| 294 | + assert "Cannot determine package name from spec" not in error |
267 | 295 |
|
268 | 296 |
|
269 | 297 | @pytest.mark.skipif(not sys.platform.startswith("win"), reason="Windows only") |
|
0 commit comments