Skip to content

Commit

Permalink
Fix failure when running within a UV venv activated shell (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Jun 27, 2024
1 parent d8bceac commit 1937c89
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ repos:
rev: "2.1.3"
hooks:
- id: pyproject-fmt
additional_dependencies: ["tox>=4.15"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.9"
hooks:
Expand Down
1 change: 1 addition & 0 deletions src/tox_uv/_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def venv_dir(self) -> Path:
@property
def environment_variables(self) -> dict[str, str]:
env = super().environment_variables
env.pop("UV_PYTHON", None) # UV_PYTHON takes precedence over VIRTUAL_ENV
env["VIRTUAL_ENV"] = str(self.venv_dir)
return env

Expand Down
10 changes: 10 additions & 0 deletions tests/test_tox_uv_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
import pytest
from tox.pytest import ToxProjectCreator


Expand Down Expand Up @@ -142,3 +143,12 @@ def test_uv_env_python_not_in_path(tox_project: ToxProjectCreator) -> None:
tox_ini = project.path / "tox.ini"
assert tox_ini.is_file()
subprocess.check_call([sys.executable, "-m", "tox", "-c", tox_ini], env=env)


def test_uv_python_set(tox_project: ToxProjectCreator, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("UV_PYTHON", sys.executable)
project = tox_project({
"tox.ini": "[testenv]\npackage=skip\ndeps=setuptools\ncommands=python -c 'import setuptools'"
})
result = project.run("-vv")
result.assert_success()

0 comments on commit 1937c89

Please sign in to comment.