Skip to content

tox can produce exception if the log folder does not exsits #3632

@ssbarnea

Description

@ssbarnea

Issue

Since yesterday, for some yet unknown reason, I am facing a very weird stacktrace exception from running tox on an environment, caused by a missing log folder. I checked the code and apparently there is the assumption that the path exists.

Probably the removal of the log folder is caused by something else but the bug is real, the code should attempt to create the path if it does not exist yet.

lint: internal error Traceback (most recent call last): File "/Users/ssbarnea/code/a/devtools/ansible-dev-tools/.tox/.tox/lib/python3.14/site-packages/tox/session/cmd/run/single.py", line 48, in _evaluate code, outcomes = run_commands(tox_env, no_test) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/code/a/devtools/ansible-dev-tools/.tox/.tox/lib/python3.14/site-packages/tox/session/cmd/run/single.py", line 85, in run_commands status_main = run_command_set(tox_env, "commands", chdir, ignore_errors, outcomes) File "/Users/ssbarnea/code/a/devtools/ansible-dev-tools/.tox/.tox/lib/python3.14/site-packages/tox/session/cmd/run/single.py", line 106, in run_command_set current_outcome = tox_env.execute( cmd.args, ...<3 lines>... run_id=f"{key}[{at}]", ) File "/Users/ssbarnea/code/a/devtools/ansible-dev-tools/.tox/.tox/lib/python3.14/site-packages/tox/tox_env/api.py", line 426, in execute with self.execute_async(cmd, stdin, show, cwd, run_id, executor) as status: ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/.config/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/contextlib.py", line 148, in __exit__ next(self.gen) ~~~~^^^^^^^^^^ File "/Users/ssbarnea/code/a/devtools/ansible-dev-tools/.tox/.tox/lib/python3.14/site-packages/tox/tox_env/api.py", line 480, in execute_async self._log_execute(request, execute_status) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/code/a/devtools/ansible-dev-tools/.tox/.tox/lib/python3.14/site-packages/tox/tox_env/api.py", line 486, in _log_execute self._write_execute_log(self.name, self.env_log_dir / f"{self._log_id}-{request.run_id}.log", request, status) ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/code/a/devtools/ansible-dev-tools/.tox/.tox/lib/python3.14/site-packages/tox/tox_env/api.py", line 490, in _write_execute_log with log_file.open("wt", encoding="utf-8") as file: ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/.config/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/pathlib/__init__.py", line 776, in open return io.open(self, mode, buffering, encoding, errors, newline) ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '/Users/ssbarnea/code/a/devtools/ansible-dev-tools/.tox/lint/log/3-commands[0].log' 

Environment

Using tox-uv, might be related.

Output of running tox

Output of tox -rvv

Minimal example

After making a patch to create the folder the exception no longer appears and I can see:

ls -1 .tox/lint/log 3-commands[0].log 

The interesting part is that executions 1 and 2 are missing. I have no pre tasks so I suspect something like packaging is removing the log file in this case.

I was able to identify that what triggers the bug is using tox-uv and setting runner = "uv-venv-lock-runner". I will try to fix this in tox-uv but I still think that we need to patch tox for creating this folder and avoid an ugly stacktrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions