Skip to content

Commit bf87bea

Browse files
authored
Override toxworkdir with --workdir. (#2776)
* Override toxworkdir with --workdir. * Override toxworkdir with --workdir. * Override toxworkdir with --workdir. * Override toxworkdir with --workdir. * Override toxworkdir with --workdir. * Override toxworkdir with --workdir. * Override toxworkdir with --workdir. * Override toxworkdir with --workdir. * Override toxworkdir with --workdir. * Override toxworkdir with --workdir. * Override toxworkdir with --workdir. * Override toxworkdir with --workdir.
1 parent a36ff9d commit bf87bea

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

docs/changelog/2654.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Override toxworkdir with --workdir.

src/tox/config/sets.py

+4
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,14 @@ def register_config(self) -> None:
191191
def work_dir_builder(conf: Config, env_name: str | None) -> Path: # noqa: U100
192192
return (conf.work_dir if conf.work_dir is not None else cast(Path, self["tox_root"])) / ".tox"
193193

194+
def work_dir_post_process(value: Path) -> Path:
195+
return self._conf.work_dir if self._conf.options.work_dir else value
196+
194197
self.add_config(
195198
keys=["work_dir", "toxworkdir"],
196199
of_type=Path,
197200
default=work_dir_builder,
201+
post_process=work_dir_post_process,
198202
desc="working directory",
199203
)
200204
self.add_config(

tests/config/test_sets.py

+8
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,11 @@ def test_set_env_raises_on_non_str(mocker: MockerFixture) -> None:
171171
env_set.loaders.insert(0, MemoryLoader(set_env=1))
172172
with pytest.raises(TypeError, match="1"):
173173
assert env_set["set_env"]
174+
175+
176+
@pytest.mark.parametrize("work_dir", ["a", ""])
177+
def test_config_work_dir(tox_project: ToxProjectCreator, work_dir: str) -> None:
178+
project = tox_project({"tox.ini": "[tox]\ntoxworkdir=b"})
179+
result = project.run("c", *(["--workdir", str(project.path / work_dir)] if work_dir else []))
180+
expected = project.path / work_dir if work_dir else Path("b")
181+
assert expected == result.state.conf.core["work_dir"]

0 commit comments

Comments
 (0)