Skip to content

test: make the remaining uv download tests pass without uv installed - #1153

Merged
henryiii merged 1 commit into
wntrblm:mainfrom
espressolee:test-uv-download-guard
Aug 3, 2026
Merged

test: make the remaining uv download tests pass without uv installed#1153
henryiii merged 1 commit into
wntrblm:mainfrom
espressolee:test-uv-download-guard

Conversation

@espressolee

Copy link
Copy Markdown
Contributor

Fixes #1045. Same root cause as #1046 — three call sites #1137 did not cover.

Reproduction on main @7519a98

$ python -m pytest tests/test_virtualenv.py -k download_python -q
33 passed

$ env -i PATH="$PWD/.venv/bin:/usr/bin:/bin" python -m pytest tests/test_virtualenv.py -k download_python -q
FAILED test_download_python_auto_missing_interpreter[uv]
FAILED test_download_python_always_preexisting_interpreter[uv]
FAILED test_download_python_range_installs_floor[always-uv]
FAILED test_download_python_range_installs_floor[auto-uv]
4 failed, 29 passed

Cause

nox/virtualenv.py:941-949:

if self.venv_backend == "uv":
    has_uv, _, uv_ver = _uv_state()
    if (
        has_uv
        and version.Version("0.4.16") <= uv_ver
        and uv_install_python(cleaned_interpreter)
    ):

Without uv on the host, has_uv is False and the mocked uv_install_python
is never reached, so assert_called_once_with(...) cannot hold.

This issue surfaces as InterpreterNotFound rather than #1046's assertion
error only because test_download_python_failed_install already wraps the call
in pytest.raises. Same short-circuit, different symptom.

Change

The guard #1137 added, applied to the three remaining tests that assert
uv_install_mock.assert_called_once_with(...). No production code touched, so
coverage is unaffected.

Verification

pytest tests/test_virtualenv.py (whole file):

without uv with uv
before 4 failed, 156 passed 7 failed, 187 passed
after 0 failed, 160 passed 7 failed, 187 passed

The 7 with-uv failures are conda tests. They are byte-identical before and
after — I diffed the two FAILED lists — and I did not investigate their
cause, since this change does not touch that path.

Removing HAS_UV from one of the three new guards turns exactly that one test
red again, so the guard is load-bearing rather than decorative.

ruff check and ruff format --check pass on the changed file.

Three tests assert `uv_install_mock.assert_called_once_with(...)` but never
reach the mock on a host without uv: `VirtualEnv._install_python()` checks
`has_uv` first and short-circuits, so the mocked `uv_install_python` is never
called.

    if self.venv_backend == "uv":
        has_uv, _, uv_ver = _uv_state()
        if has_uv and version.Version("0.4.16") <= uv_ver and uv_install_python(...):

Same root cause as wntrblmgh-1046, which wntrblm#1137 fixed for
`test_download_python_failed_install` by pretending uv is available. This
applies that guard to the three sibling tests it did not cover.

wntrblmgh-1045 surfaces as `InterpreterNotFound` rather than wntrblmgh-1046's assertion
error only because `test_download_python_failed_install` already wraps the
call in `pytest.raises`.

Measured on 7519a98, `pytest tests/test_virtualenv.py`:

                 without uv              with uv
    before       4 failed, 156 passed    7 failed, 187 passed
    after        0 failed, 160 passed    7 failed, 187 passed

The 7 with-uv failures are conda tests, identical before and after; their
cause was not investigated. Removing `HAS_UV` from one of the three guards
turns exactly that test red again.

Fixes wntrblm#1045

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@henryiii
henryiii merged commit 2b1ad76 into wntrblm:main Aug 3, 2026
22 checks passed
@henryiii

henryiii commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks! I swapped the Claude coauthor for Assisted-by when squashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

nox.virtualenv.InterpreterNotFound: Python interpreter python3.11 not found

2 participants