From 5508b21d9fea70a8ddfc3d0a22cff9f1a9636d13 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Mon, 16 Jan 2023 23:09:25 -0800 Subject: [PATCH 1/2] test_provision_conf_file: provision outside of {tox_root} using either a relative or absolute path to the conf file --- tests/test_provision.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_provision.py b/tests/test_provision.py index 91d7689df..4a5bc1a2c 100644 --- a/tests/test_provision.py +++ b/tests/test_provision.py @@ -212,3 +212,17 @@ def test_provision_plugin_runner_in_provision(tox_project: ToxProjectCreator, tm proj = tox_project({"tox.ini": "[tox]\nrequires=somepkg123xyz\n[testenv:.tox]\nrunner=example"}) with pytest.raises(KeyError, match="example"): proj.run("r", "-e", "py", "--result-json", str(log)) + + +@pytest.mark.integration() +@pytest.mark.usefixtures("_pypi_index_self") +@pytest.mark.parametrize("relative_path", [True, False], ids=["relative", "absolute"]) +def test_provision_conf_file(tox_project: ToxProjectCreator, tmp_path: Path, relative_path: bool) -> None: + ini = "[tox]\nrequires = demo-pkg-inline\nskipsdist=true\n" + project = tox_project({"tox.ini": ini}, prj_path=tmp_path / "sub") + if relative_path: + conf_path = os.path.join(project.path.name, "tox.ini") + else: + conf_path = str(project.path / "tox.ini") + result = project.run("c", "--conf", conf_path, "-e", "py", from_cwd=tmp_path) + result.assert_success() From 6e621b752cb2f1dca2b7116ca2ad9e79f5938738 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Mon, 16 Jan 2023 23:10:18 -0800 Subject: [PATCH 2/2] run provisioned tox in current working directory instead of {tox_root} running in a different working directory than the parent process changes the interpretation of relative paths on the command line passed to the provisoned tox and must be avoided. fix #2876 --- docs/changelog/2876.bugfix.rst | 7 +++++++ src/tox/provision.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/2876.bugfix.rst diff --git a/docs/changelog/2876.bugfix.rst b/docs/changelog/2876.bugfix.rst new file mode 100644 index 000000000..94f547562 --- /dev/null +++ b/docs/changelog/2876.bugfix.rst @@ -0,0 +1,7 @@ +When executing via the provisioning environment (``.tox`` by default), run +``tox`` in working directory of the parent process. + +Prior to this change (from tox 4.0.0), the provisioned ``tox`` would execute with +``{tox_root}`` as the working directory, which breaks when a relative path is +passed to ``-c`` or ``--conf`` and ``tox`` is executed in a working directory +other than ``{tox_root}`` - by :user:`masenf`. diff --git a/src/tox/provision.py b/src/tox/provision.py index 9b1aeba5f..e67121bd8 100644 --- a/src/tox/provision.py +++ b/src/tox/provision.py @@ -150,5 +150,5 @@ def run_provision(name: str, state: State) -> int: raise HandledError(f"cannot provision tox environment {tox_env.conf['env_name']} because {exception}") args: list[str] = [str(env_python), "-m", "tox"] args.extend(state.args) - outcome = tox_env.execute(cmd=args, stdin=StdinSource.user_only(), show=True, run_id="provision") + outcome = tox_env.execute(cmd=args, stdin=StdinSource.user_only(), show=True, run_id="provision", cwd=Path.cwd()) return cast(int, outcome.exit_code)