diff --git a/tests/test_discovery.py b/tests/test_discovery.py index c418114..73d6f84 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -1,5 +1,6 @@ from __future__ import annotations +import copy import logging import os import stat @@ -138,14 +139,17 @@ def test_discovery_invalid_specifier_raises(session_cache: DiskCache) -> None: [pytest.param(False, id="list"), pytest.param(True, id="iterator")], ) def test_discovery_fallback_reuses_preferred_paths( - tmp_path: Path, session_cache: DiskCache, *, use_iterator: bool + tmp_path: Path, session_cache: DiskCache, mocker: MockerFixture, *, use_iterator: bool ) -> None: - preferred = tmp_path / "preferred" - subprocess.check_call([sys.executable, "-m", "venv", "--without-pip", "--copies", str(preferred)]) - executable = preferred / ("Scripts/python.exe" if IS_WIN else "bin/python") + executable = tmp_path / "preferred" / ("Scripts/python.exe" if IS_WIN else "bin/python") + executable.parent.mkdir(parents=True) + executable.touch() + preferred_info = copy.deepcopy(PythonInfo.current_system(session_cache)) + preferred_info.executable = str(executable) + mocker.patch.object(PythonInfo, "from_exe", return_value=preferred_info) paths = [str(executable)] result = get_interpreter( - ["missing-interpreter", str(sys.version_info.major)], + ["missing-interpreter", ">=3"], try_first_with=iter(paths) if use_iterator else paths, cache=session_cache, env={**os.environ, "PATH": str(tmp_path), "UV_PYTHON_INSTALL_DIR": str(tmp_path / "missing")}, @@ -157,7 +161,7 @@ def test_discovery_fallback_reuses_preferred_paths( def test_discovery_stops_reading_preferred_paths_after_match(session_cache: DiskCache) -> None: preferred_paths = iter([sys.executable, "unneeded"]) - result = get_interpreter(str(sys.version_info.major), try_first_with=preferred_paths, cache=session_cache) + result = get_interpreter(">=3", try_first_with=preferred_paths, cache=session_cache) assert result is not None assert next(preferred_paths) == "unneeded"