Skip to content

Commit 2a87375

Browse files
authored
Provision cwd (#2877)
Fix #2876
1 parent 1ba0419 commit 2a87375

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

docs/changelog/2876.bugfix.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
When executing via the provisioning environment (``.tox`` by default), run
2+
``tox`` in working directory of the parent process.
3+
4+
Prior to this change (from tox 4.0.0), the provisioned ``tox`` would execute with
5+
``{tox_root}`` as the working directory, which breaks when a relative path is
6+
passed to ``-c`` or ``--conf`` and ``tox`` is executed in a working directory
7+
other than ``{tox_root}`` - by :user:`masenf`.

src/tox/provision.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,5 @@ def run_provision(name: str, state: State) -> int:
150150
raise HandledError(f"cannot provision tox environment {tox_env.conf['env_name']} because {exception}")
151151
args: list[str] = [str(env_python), "-m", "tox"]
152152
args.extend(state.args)
153-
outcome = tox_env.execute(cmd=args, stdin=StdinSource.user_only(), show=True, run_id="provision")
153+
outcome = tox_env.execute(cmd=args, stdin=StdinSource.user_only(), show=True, run_id="provision", cwd=Path.cwd())
154154
return cast(int, outcome.exit_code)

tests/test_provision.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,17 @@ def test_provision_plugin_runner_in_provision(tox_project: ToxProjectCreator, tm
212212
proj = tox_project({"tox.ini": "[tox]\nrequires=somepkg123xyz\n[testenv:.tox]\nrunner=example"})
213213
with pytest.raises(KeyError, match="example"):
214214
proj.run("r", "-e", "py", "--result-json", str(log))
215+
216+
217+
@pytest.mark.integration()
218+
@pytest.mark.usefixtures("_pypi_index_self")
219+
@pytest.mark.parametrize("relative_path", [True, False], ids=["relative", "absolute"])
220+
def test_provision_conf_file(tox_project: ToxProjectCreator, tmp_path: Path, relative_path: bool) -> None:
221+
ini = "[tox]\nrequires = demo-pkg-inline\nskipsdist=true\n"
222+
project = tox_project({"tox.ini": ini}, prj_path=tmp_path / "sub")
223+
if relative_path:
224+
conf_path = os.path.join(project.path.name, "tox.ini")
225+
else:
226+
conf_path = str(project.path / "tox.ini")
227+
result = project.run("c", "--conf", conf_path, "-e", "py", from_cwd=tmp_path)
228+
result.assert_success()

0 commit comments

Comments
 (0)