tox-dev / tox-uv

Use https://github.com/astral-sh/uv with tox
MIT License
76 stars 15 forks source link

Fails to run test for on the defined Python versions, except on uv's pinned Python version. #97

Open flowgunso opened 6 hours ago

flowgunso commented 6 hours ago

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

Output of uv --version of the host Python. ```console uv 0.4.14 ```
Output of tox --version of the host Python. Tox was installed using uv tool install tox --with tox-uv ```console 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 ```console 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. ```console 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 ```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 ```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 ```Makefile sync: uv sync tests: uv run pytest --cov=env tests.py ```
gaborbernat commented 5 hours ago

Do you have a docker image where you can replicate this? It doesn't replicate for me with the information provided.