Skip to content

Commit

Permalink
tests: add tests for installed UV
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Apr 15, 2024
1 parent 3b8e081 commit c18f2ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import os
import pathlib
import re
import subprocess
import shutil
import subprocess
import sys
import unicodedata
from collections.abc import (
Expand Down Expand Up @@ -562,7 +562,7 @@ def _run(
self.virtualenv.venv_backend == "uv"
and args[0] == "uv"
and nox.virtualenv.UV != "uv"
and shutil.which("uv", path=self.bin) is None
and shutil.which("uv", path=self.bin) is None # Session uv takes priority
):
args = (nox.virtualenv.UV, *args[1:])

Expand Down
20 changes: 19 additions & 1 deletion tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ class SessionNoSlots(nox.sessions.Session):
session = SessionNoSlots(runner=runner)

monkeypatch.setattr(nox.virtualenv, "UV", "/some/uv")
monkeypatch.setattr(shutil, "which", lambda x: None)
monkeypatch.setattr(shutil, "which", lambda x, path=None: None)

with mock.patch.object(nox.command, "run", autospec=True) as run:
session.install("requests", "urllib3", silent=False)
Expand All @@ -910,6 +910,24 @@ class SessionNoSlots(nox.sessions.Session):
"urllib3",
)

# user installs uv in the session venv
monkeypatch.setattr(
shutil, "which", lambda x, path="": path + "/uv" if x == "uv" else 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 == (
"uv",
"pip",
"install",
"requests",
"urllib3",
)

def test___slots__(self):
session, _ = self.make_session_and_runner()
with pytest.raises(AttributeError):
Expand Down

0 comments on commit c18f2ca

Please sign in to comment.