Skip to content

Commit

Permalink
Override toxworkdir with --workdir.
Browse files Browse the repository at this point in the history
  • Loading branch information
q0w committed Dec 26, 2022
1 parent a36ff9d commit 2f2137d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2654.bugfix.rst
@@ -0,0 +1 @@
Override toxworkdir with --workdir.
7 changes: 4 additions & 3 deletions src/tox/config/sets.py
Expand Up @@ -188,13 +188,14 @@ def register_config(self) -> None:
desc="the root directory (where the configuration file is found)",
)

def work_dir_builder(conf: Config, env_name: str | None) -> Path: # noqa: U100
return (conf.work_dir if conf.work_dir is not None else cast(Path, self["tox_root"])) / ".tox"
def work_dir_post_process(value: Path) -> Path:
return self._conf.work_dir / ".tox" if self._conf.work_dir is not None else value

self.add_config(
keys=["work_dir", "toxworkdir"],
of_type=Path,
default=work_dir_builder,
default=self["tox_root"] / ".tox",
post_process=work_dir_post_process,
desc="working directory",
)
self.add_config(
Expand Down
8 changes: 8 additions & 0 deletions tests/config/test_sets.py
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
from collections import OrderedDict
from pathlib import Path
from typing import Callable, Dict, Optional, Set, TypeVar
Expand Down Expand Up @@ -171,3 +172,10 @@ def test_set_env_raises_on_non_str(mocker: MockerFixture) -> None:
env_set.loaders.insert(0, MemoryLoader(set_env=1))
with pytest.raises(TypeError, match="1"):
assert env_set["set_env"]


def test_config_work_dir(tox_project: ToxProjectCreator) -> None:
project = tox_project({"tox.ini": "[tox]\ntoxworkdir=/tmp/foo"})
work_dir_flag = "/tmp/bar"
result = project.run("c", "-k", "toxworkdir", "--core", "--workdir", work_dir_flag)
assert f"work_dir = {os.path.join(work_dir_flag,'.tox')}{os.linesep}" in result.out

0 comments on commit 2f2137d

Please sign in to comment.