tox-uv: Fails to run test for on the defined Python versions, except on uv's pinned Python version.

Issue

Tox does not manage to run the tests on the defined Python version list, but it does manage to run the tests on the Python version pinned with uv. The remaining fails when trying to create a log file.

FileNotFoundError: [Errno 2] No such file or directory: '/home/[...]/snippets/get_configuration/.tox/py312/log/2-uv-sync.log'

The log/ directory does not exist. Creating it prior to running tox does not solves the issue.

Environment

  • OS: Ubuntu 22.04.4 LTS
Output of uv --version of the host Python.
uv 0.4.14
Output of tox --version of the host Python. Tox was installed using uv tool install tox --with tox-uv
4.20.0 from /home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/__init__.py
registered plugins:
    tox-uv-1.13.0 at /home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox_uv/plugin.py with uv==0.4.14

Output of running tox

Output of tox -rvv
py38: 209 W remove tox env folder /home/[...]/snippets/get_configuration/.tox/py38 [tox/tox_env/api.py:324]
py38: 214 W venv> /home/[...]/.local/share/uv/tools/tox/bin/uv venv -p 3.8 --allow-existing -v --python-preference only-managed /home/[...]/snippets/get_configuration/.tox/py38 [tox/tox_env/api.py:426]
DEBUG uv 0.4.14
DEBUG Found project root: `/home/[...]/snippets/get_configuration`
DEBUG No workspace root found, using project root
DEBUG Searching for Python 3.8 in managed installations
DEBUG Searching for managed installations at `/home/[...]/.local/share/uv/python`
DEBUG Found managed installation `cpython-3.8.19-linux-x86_64-gnu`
DEBUG Found `cpython-3.8.19-linux-x86_64-gnu` at `/home/[...]/.local/share/uv/python/cpython-3.8.19-linux-x86_64-gnu/bin/python3` (managed installations)
Using Python 3.8.19
Creating virtual environment at: .tox/py38
DEBUG Allowing existing directory
py38: 231 I exit 0 (0.02 seconds) /home/[...]/snippets/get_configuration> /home/[...]/.local/share/uv/tools/tox/bin/uv venv -p 3.8 --allow-existing -v --python-preference only-managed /home/[...]/snippets/get_configuration/.tox/py38 pid=1729520 [tox/execute/api.py:286]
py38: 233 W uv-sync> uv sync --frozen --no-dev [tox/tox_env/api.py:426]
py38: 254 E internal error [tox/session/cmd/run/single.py:60]
Traceback (most recent call last):
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/session/cmd/run/single.py", line 47, in _evaluate
    tox_env.setup()
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 249, in setup
    self._setup_env()
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox_uv/_run_lock.py", line 59, in _setup_env
    outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="uv-sync", show=False)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 388, in execute
    with self.execute_async(cmd, stdin, show, cwd, run_id, executor) as status:
  File "/home/[...]/.local/share/uv/python/cpython-3.12.5-linux-x86_64-gnu/lib/python3.12/contextlib.py", line 144, in __exit__
    next(self.gen)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 442, in execute_async
    self._log_execute(request, execute_status)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 448, in _log_execute
    self._write_execute_log(self.name, self.env_log_dir / f"{self._log_id}-{request.run_id}.log", request, status)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 452, in _write_execute_log
    with log_file.open("wt", encoding="utf-8") as file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[...]/.local/share/uv/python/cpython-3.12.5-linux-x86_64-gnu/lib/python3.12/pathlib.py", line 1013, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/[...]/snippets/get_configuration/.tox/py38/log/2-uv-sync.log'
py38: FAIL ✖ in 0.05 seconds
py39: 256 W remove tox env folder /home/[...]/snippets/get_configuration/.tox/py39 [tox/tox_env/api.py:324]
py39: 260 W venv> /home/[...]/.local/share/uv/tools/tox/bin/uv venv -p 3.9 --allow-existing -v --python-preference only-managed /home/[...]/snippets/get_configuration/.tox/py39 [tox/tox_env/api.py:426]
DEBUG uv 0.4.14
DEBUG Found project root: `/home/[...]/snippets/get_configuration`
DEBUG No workspace root found, using project root
DEBUG Searching for Python 3.9 in managed installations
DEBUG Searching for managed installations at `/home/[...]/.local/share/uv/python`
DEBUG Found managed installation `cpython-3.9.19-linux-x86_64-gnu`
DEBUG Found `cpython-3.9.19-linux-x86_64-gnu` at `/home/[...]/.local/share/uv/python/cpython-3.9.19-linux-x86_64-gnu/bin/python3` (managed installations)
Using Python 3.9.19
Creating virtual environment at: .tox/py39
DEBUG Allowing existing directory
py39: 280 I exit 0 (0.02 seconds) /home/[...]/snippets/get_configuration> /home/[...]/.local/share/uv/tools/tox/bin/uv venv -p 3.9 --allow-existing -v --python-preference only-managed /home/[...]/snippets/get_configuration/.tox/py39 pid=1729555 [tox/execute/api.py:286]
py39: 281 W uv-sync> uv sync --frozen --no-dev [tox/tox_env/api.py:426]
py39: 305 E internal error [tox/session/cmd/run/single.py:60]
Traceback (most recent call last):
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/session/cmd/run/single.py", line 47, in _evaluate
    tox_env.setup()
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 249, in setup
    self._setup_env()
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox_uv/_run_lock.py", line 59, in _setup_env
    outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="uv-sync", show=False)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 388, in execute
    with self.execute_async(cmd, stdin, show, cwd, run_id, executor) as status:
  File "/home/[...]/.local/share/uv/python/cpython-3.12.5-linux-x86_64-gnu/lib/python3.12/contextlib.py", line 144, in __exit__
    next(self.gen)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 442, in execute_async
    self._log_execute(request, execute_status)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 448, in _log_execute
    self._write_execute_log(self.name, self.env_log_dir / f"{self._log_id}-{request.run_id}.log", request, status)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 452, in _write_execute_log
    with log_file.open("wt", encoding="utf-8") as file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[...]/.local/share/uv/python/cpython-3.12.5-linux-x86_64-gnu/lib/python3.12/pathlib.py", line 1013, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/[...]/snippets/get_configuration/.tox/py39/log/2-uv-sync.log'
py39: FAIL ✖ in 0.05 seconds
py310: 307 W remove tox env folder /home/[...]/snippets/get_configuration/.tox/py310 [tox/tox_env/api.py:324]
py310: 318 W venv> /home/[...]/.local/share/uv/tools/tox/bin/uv venv -p 3.10 --allow-existing -v --python-preference only-managed /home/[...]/snippets/get_configuration/.tox/py310 [tox/tox_env/api.py:426]
DEBUG uv 0.4.14
DEBUG Found project root: `/home/[...]/snippets/get_configuration`
DEBUG No workspace root found, using project root
DEBUG Searching for Python 3.10 in managed installations
DEBUG Searching for managed installations at `/home/[...]/.local/share/uv/python`
DEBUG Found managed installation `cpython-3.10.14-linux-x86_64-gnu`
DEBUG Found `cpython-3.10.14-linux-x86_64-gnu` at `/home/[...]/.local/share/uv/python/cpython-3.10.14-linux-x86_64-gnu/bin/python3` (managed installations)
Using Python 3.10.14
Creating virtual environment at: .tox/py310
DEBUG Allowing existing directory
py310: 338 I exit 0 (0.02 seconds) /home/[...]/snippets/get_configuration> /home/[...]/.local/share/uv/tools/tox/bin/uv venv -p 3.10 --allow-existing -v --python-preference only-managed /home/[...]/snippets/get_configuration/.tox/py310 pid=1729591 [tox/execute/api.py:286]
py310: 340 W uv-sync> uv sync --frozen --no-dev [tox/tox_env/api.py:426]
py310: 366 E internal error [tox/session/cmd/run/single.py:60]
Traceback (most recent call last):
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/session/cmd/run/single.py", line 47, in _evaluate
    tox_env.setup()
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 249, in setup
    self._setup_env()
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox_uv/_run_lock.py", line 59, in _setup_env
    outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="uv-sync", show=False)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 388, in execute
    with self.execute_async(cmd, stdin, show, cwd, run_id, executor) as status:
  File "/home/[...]/.local/share/uv/python/cpython-3.12.5-linux-x86_64-gnu/lib/python3.12/contextlib.py", line 144, in __exit__
    next(self.gen)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 442, in execute_async
    self._log_execute(request, execute_status)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 448, in _log_execute
    self._write_execute_log(self.name, self.env_log_dir / f"{self._log_id}-{request.run_id}.log", request, status)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 452, in _write_execute_log
    with log_file.open("wt", encoding="utf-8") as file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[...]/.local/share/uv/python/cpython-3.12.5-linux-x86_64-gnu/lib/python3.12/pathlib.py", line 1013, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/[...]/snippets/get_configuration/.tox/py310/log/2-uv-sync.log'
py311: 368 W remove tox env folder /home/[...]/snippets/get_configuration/.tox/py311 [tox/tox_env/api.py:324]
py310: FAIL ✖ in 0.06 seconds
py311: 391 W venv> /home/[...]/.local/share/uv/tools/tox/bin/uv venv -p 3.11 --allow-existing -v --python-preference only-managed /home/[...]/snippets/get_configuration/.tox/py311 [tox/tox_env/api.py:426]
DEBUG uv 0.4.14
DEBUG Found project root: `/home/[...]/snippets/get_configuration`
DEBUG No workspace root found, using project root
DEBUG Searching for Python 3.11 in managed installations
DEBUG Searching for managed installations at `/home/[...]/.local/share/uv/python`
DEBUG Found managed installation `cpython-3.11.9-linux-x86_64-gnu`
DEBUG Found `cpython-3.11.9-linux-x86_64-gnu` at `/home/[...]/.local/share/uv/python/cpython-3.11.9-linux-x86_64-gnu/bin/python3` (managed installations)
Using Python 3.11.9
Creating virtual environment at: .tox/py311
DEBUG Allowing existing directory
py311: 411 I exit 0 (0.02 seconds) /home/[...]/snippets/get_configuration> /home/[...]/.local/share/uv/tools/tox/bin/uv venv -p 3.11 --allow-existing -v --python-preference only-managed /home/[...]/snippets/get_configuration/.tox/py311 pid=1729626 [tox/execute/api.py:286]
py311: 413 W uv-sync> uv sync --frozen --no-dev [tox/tox_env/api.py:426]
py311: 430 I exit 0 (0.02 seconds) /home/[...]/snippets/get_configuration> uv sync --frozen --no-dev pid=1729645 [tox/execute/api.py:286]
py311: 431 W commands[0]> make tests [tox/tox_env/api.py:426]
uv run pytest --cov=env tests.py
Installed 7 packages in 12ms
================================================ test session starts ================================================
platform linux -- Python 3.11.9, pytest-8.3.3, pluggy-1.5.0
cachedir: .tox/py311/.pytest_cache
rootdir: /home/[...]/snippets/get_configuration
configfile: pyproject.toml
plugins: cov-5.0.0, mock-3.14.0
collected 6 items                                                                                                   

tests.py ......                                                                                               [100%]

---------- coverage: platform linux, python 3.11.9-final-0 -----------
Name                       Stmts   Miss  Cover
----------------------------------------------
src/env/__init__.py            2      0   100%
src/env/configuration.py      24      0   100%
----------------------------------------------
TOTAL                         26      0   100%


================================================= 6 passed in 0.07s =================================================
py311: 1349 I exit 0 (0.92 seconds) /home/[...]/snippets/get_configuration> make tests pid=1729659 [tox/execute/api.py:286]
py311: OK ✔ in 0.98 seconds
py312: 1349 W remove tox env folder /home/[...]/snippets/get_configuration/.tox/py312 [tox/tox_env/api.py:324]
py312: 1357 W venv> /home/[...]/.local/share/uv/tools/tox/bin/uv venv -p /home/[...]/.local/share/uv/tools/tox/bin/python --allow-existing -v --python-preference only-managed /home/[...]/snippets/get_configuration/.tox/py312 [tox/tox_env/api.py:426]
DEBUG uv 0.4.14
DEBUG Found project root: `/home/[...]/snippets/get_configuration`
DEBUG No workspace root found, using project root
DEBUG Checking for Python interpreter at path `/home/[...]/.local/share/uv/tools/tox/bin/python`
Using Python 3.12.5 interpreter at: /home/[...]/.local/share/uv/tools/tox/bin/python
Creating virtual environment at: .tox/py312
DEBUG Allowing existing directory
py312: 1380 I exit 0 (0.02 seconds) /home/[...]/snippets/get_configuration> /home/[...]/.local/share/uv/tools/tox/bin/uv venv -p /home/[...]/.local/share/uv/tools/tox/bin/python --allow-existing -v --python-preference only-managed /home/[...]/snippets/get_configuration/.tox/py312 pid=1729739 [tox/execute/api.py:286]
py312: 1382 W uv-sync> uv sync --frozen --no-dev [tox/tox_env/api.py:426]
py312: 1407 E internal error [tox/session/cmd/run/single.py:60]
Traceback (most recent call last):
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/session/cmd/run/single.py", line 47, in _evaluate
    tox_env.setup()
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 249, in setup
    self._setup_env()
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox_uv/_run_lock.py", line 59, in _setup_env
    outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="uv-sync", show=False)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 388, in execute
    with self.execute_async(cmd, stdin, show, cwd, run_id, executor) as status:
  File "/home/[...]/.local/share/uv/python/cpython-3.12.5-linux-x86_64-gnu/lib/python3.12/contextlib.py", line 144, in __exit__
    next(self.gen)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 442, in execute_async
    self._log_execute(request, execute_status)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 448, in _log_execute
    self._write_execute_log(self.name, self.env_log_dir / f"{self._log_id}-{request.run_id}.log", request, status)
  File "/home/[...]/.local/share/uv/tools/tox/lib/python3.12/site-packages/tox/tox_env/api.py", line 452, in _write_execute_log
    with log_file.open("wt", encoding="utf-8") as file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/[...]/.local/share/uv/python/cpython-3.12.5-linux-x86_64-gnu/lib/python3.12/pathlib.py", line 1013, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/[...]/snippets/get_configuration/.tox/py312/log/2-uv-sync.log'
  py38: FAIL code 2 (0.05 seconds)
  py39: FAIL code 2 (0.05 seconds)
  py310: FAIL code 2 (0.06 seconds)
  py311: OK (0.98=setup[0.06]+cmd[0.92] seconds)
  py312: FAIL code 2 (0.06 seconds)
  evaluation failed :( (1.27 seconds)

Any Python version pinned with uv will pass without any issues, and sometimes, the two most recent pinned Python version will also pass.

Trimmed output of tox showing only the report, after the Python version 3.8 then 3.9 were pinned.
  py38: OK (1.10=setup[0.04]+cmd[1.06] seconds)
  py39: OK (0.97=setup[0.03]+cmd[0.94] seconds)
  py310: FAIL code 2 (0.04 seconds)
  py311: FAIL code 2 (0.14 seconds)
  py312: FAIL code 2 (0.06 seconds)
  evaluation failed :( (2.39 seconds)

Related code

You can find the whole related code in the Gitlab snippet 1941025, but here are the tox.ini, pyproject.toml and the Makefile:

tox.ini
[tox]
env_list = py{38,39,310,311,312}

[testenv]
description = run unit tests
runner = uv-venv-lock-runner

allowlist_externals = make
commands =
    make tests
pyproject.toml

[project]
name = "env"
version = "3.1.0"
description = """
A helper function to retrieve configuration values from environment variables or Docker secrets. 
The function supports reading secrets from files (if *_FILE is set) and can return default values 
when no environment variable is found. Raises appropriate exceptions when required configuration 
is missing or when errors occur during file reading.
"""
readme = "README.md"
requires-python = ">=3.8"

[tool.uv]
dev-dependencies = [
    "pytest>=8.3.3",
    "pytest-mock>=3.14.0",
    "pytest-cov>=5.0.0",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
Makefile
sync:
	uv sync

tests:
	uv run pytest --cov=env tests.py

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

@DavidWalshe93 thanks for the in-depth description. I’ve found another solution, after the issue solved itself with a system update.

Instead of using uv in the make target, like you pointed out, I’m using uv in the tox commands:

[tox]
env_list = py{38,39,310,311,312}

[testenv]
description = run unit tests
runner = uv-venv-lock-runner
allowlist_externals = make
commands =
    uv run pytest --cov=env_secrets tests/

And then, I’m using tox in the make target directly.

test:
	tox

That works as well.

Sure, I’ve pushed the image to Docker Hub, you can get it from the image flowgunso/env, it calls tox directly. You can find the full code in the Gitlab snippet 1941025, though.

I wasn’t sure how to link tox and tox-uv from uv with the system itself. That’s why I’ve installed tox with pipx. Reading uv’s documentation, I’ve learned about uv tool update-shell that makes sure ~/.local/bin is in my PATH.

I’ve updated the Dockerfile accordingly:

FROM python:3-bookworm

COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

WORKDIR /opt/env
COPY . .
RUN uv sync && \
    uv tool install tox --with tox-uv

ENV PATH="$PATH:/root/.local/bin"

CMD [ "tox" ]

Thanks for you help.