Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog/2562.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ensure paths constructed by tox are stable by resolving relative paths to fully qualified one, this insures that running
tox from a different folder than project root still generates meaningful paths - by :user:`gaborbernat`.
4 changes: 3 additions & 1 deletion src/tox/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def __init__(
pos_args: Sequence[str] | None,
work_dir: Path,
) -> None:

self._pos_args = None if pos_args is None else tuple(pos_args)
self._work_dir = work_dir
self._root = root
Expand Down Expand Up @@ -93,6 +92,9 @@ def make(cls, parsed: Parsed, pos_args: Sequence[str] | None, source: Source) ->
# work dir is where we put our own files
root: Path = source.path.parent if parsed.root_dir is None else parsed.root_dir
work_dir: Path = source.path.parent if parsed.work_dir is None else parsed.work_dir
# if these are relative we need to expand them them to ensure paths built on this can resolve independent on cwd
root = root.resolve()
work_dir = work_dir.resolve()
return cls(
config_source=source,
options=parsed,
Expand Down
17 changes: 17 additions & 0 deletions tests/config/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
from pathlib import Path

from tests.conftest import ToxIniCreator
from tox.config.loader.api import Override
Expand Down Expand Up @@ -83,3 +84,19 @@ def test_args_are_paths_when_with_change_dir(tox_project: ToxProjectCreator) ->
result = project.run("c", "-e", "py", "-k", "commands", "--", *args)
result.assert_success()
assert result.out == f"[testenv:py]\ncommands = magic.py {project.path} ..{os.sep}tox.ini a.txt . ..\n"


def test_relative_config_paths_resolve(tox_project: ToxProjectCreator) -> None:
project = tox_project({"tox.ini": "[tox]"})
result = project.run(
"c",
"-c",
str(Path(project.path.name) / "tox.ini"),
"-k",
"change_dir",
"env_dir",
from_cwd=project.path.parent,
)
result.assert_success()
expected = f"[testenv:py]\nchange_dir = {project.path}\nenv_dir = {project.path / '.tox' / 'py'}\n\n[tox]\n"
assert result.out == expected