diff --git a/nox/sessions.py b/nox/sessions.py index e4007f2a..b51161a6 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -557,8 +557,12 @@ def _run( return self._run_func(args[0], args[1:]) # type: ignore[unreachable] # Using `"uv"` when `uv` is the backend is guaranteed to work, even if it was co-installed with nox. - if self.virtualenv.venv_backend == "uv" and args[0] == "uv" and nox.virtualenv.UV != "uv": - args = (nox.virualenv.UV, *args[1:]) + if ( + self.virtualenv.venv_backend == "uv" + and args[0] == "uv" + and nox.virtualenv.UV != "uv" + ): + args = (nox.virtualenv.UV, *args[1:]) # Combine the env argument with our virtualenv's env vars. if include_outer_env: diff --git a/tests/test_sessions.py b/tests/test_sessions.py index 17237e1a..76e67a14 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -849,8 +849,7 @@ def test_session_venv_reused_with_no_install(self, no_install, reused, run_calle assert run.called is run_called - @pytest.mark.parametrize("uv", [None, "/some/uv"]) - def test_install_uv(self, uv, monkeypatch): + def test_install_uv(self): runner = nox.sessions.SessionRunner( name="test", signatures=["test"], @@ -867,13 +866,10 @@ class SessionNoSlots(nox.sessions.Session): session = SessionNoSlots(runner=runner) - if uv is not None: - monkeypatch.setattr(nox.virtualenv, "UV", uv) - with mock.patch.object(session, "_run", autospec=True) as run: session.install("requests", "urllib3", silent=False) run.assert_called_once_with( - nox.virtualenv.UV, + "uv", "pip", "install", "requests", @@ -881,6 +877,39 @@ class SessionNoSlots(nox.sessions.Session): **_run_with_defaults(silent=False, external="error"), ) + def test_install_uv_command(self, monkeypatch): + runner = nox.sessions.SessionRunner( + name="test", + signatures=["test"], + func=mock.sentinel.func, + global_config=_options.options.namespace(posargs=[]), + manifest=mock.create_autospec(nox.manifest.Manifest), + ) + runner.venv = mock.create_autospec(nox.virtualenv.VirtualEnv) + runner.venv.env = {} + runner.venv.venv_backend = "uv" + + class SessionNoSlots(nox.sessions.Session): + pass + + session = SessionNoSlots(runner=runner) + + monkeypatch.setattr(nox.virtualenv, "UV", "/some/uv") + monkeypatch.setattr(shutil, "which", lambda x: None) + + with mock.patch.object(nox.command, "run", autospec=True) as run: + session.install("requests", "urllib3", silent=False) + run.assert_called_once() + + ((call_args,), _) = run.call_args + assert call_args == ( + "/some/uv", + "pip", + "install", + "requests", + "urllib3", + ) + def test___slots__(self): session, _ = self.make_session_and_runner() with pytest.raises(AttributeError):