Skip to content

Override toxworkdir with --workdir. #2776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 26, 2022
1 change: 1 addition & 0 deletions docs/changelog/2654.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Override toxworkdir with --workdir.
4 changes: 4 additions & 0 deletions src/tox/config/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,14 @@ def register_config(self) -> None:
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 if self._conf.options.work_dir else value

self.add_config(
keys=["work_dir", "toxworkdir"],
of_type=Path,
default=work_dir_builder,
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
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,11 @@ 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"]


@pytest.mark.parametrize("work_dir", ["a", ""])
def test_config_work_dir(tox_project: ToxProjectCreator, work_dir: str) -> None:
project = tox_project({"tox.ini": "[tox]\ntoxworkdir=b"})
result = project.run("c", *(["--workdir", str(project.path / work_dir)] if work_dir else []))
expected = project.path / work_dir if work_dir else Path("b")
assert expected == result.state.conf.core["work_dir"]