|
8 | 8 | from tox.config.loader.api import Override, apply_overrides_to_raw |
9 | 9 |
|
10 | 10 | if TYPE_CHECKING: |
11 | | - from tox.pytest import CaptureFixture |
| 11 | + from tox.pytest import CaptureFixture, ToxProjectCreator |
12 | 12 |
|
13 | 13 |
|
14 | 14 | @pytest.mark.parametrize("flag", ["-x", "--override"]) |
@@ -109,3 +109,46 @@ def test_apply_overrides_to_raw_ignores_other_keys() -> None: |
109 | 109 | def test_apply_overrides_to_raw_append_unsupported_type() -> None: |
110 | 110 | with pytest.raises(ValueError, match="Only able to append to lists, dicts and strings"): |
111 | 111 | apply_overrides_to_raw([Override("ns.k+=1")], "k", 0) |
| 112 | + |
| 113 | + |
| 114 | +@pytest.mark.parametrize( |
| 115 | + ("filename", "content", "namespace"), |
| 116 | + [ |
| 117 | + pytest.param( |
| 118 | + "tox.toml", |
| 119 | + 'env_list = ["a"]\n[env_run_base]\nskip_install = true\ncommands = [["python"]]\n', |
| 120 | + "env_run_base", |
| 121 | + id="toml", |
| 122 | + ), |
| 123 | + pytest.param( |
| 124 | + "tox.ini", |
| 125 | + "[tox]\nenv_list = a\n[testenv]\nskip_install = true\ncommands = python\n", |
| 126 | + "testenv", |
| 127 | + id="ini", |
| 128 | + ), |
| 129 | + ], |
| 130 | +) |
| 131 | +@pytest.mark.parametrize( |
| 132 | + ("override", "posargs", "expected"), |
| 133 | + [ |
| 134 | + pytest.param("python {posargs}", ["--", "tests", "src"], "python tests src", id="posargs"), |
| 135 | + pytest.param("python {posargs:tests}", [], "python tests", id="posargs-default"), |
| 136 | + pytest.param("python {env:MAGIC}", [], "python from-env", id="env"), |
| 137 | + pytest.param("python {env_name}", [], "python a", id="env-name"), |
| 138 | + ], |
| 139 | +) |
| 140 | +def test_override_value_is_substituted( |
| 141 | + tox_project: ToxProjectCreator, |
| 142 | + monkeypatch: pytest.MonkeyPatch, |
| 143 | + filename: str, |
| 144 | + content: str, |
| 145 | + namespace: str, |
| 146 | + override: str, |
| 147 | + posargs: list[str], |
| 148 | + expected: str, |
| 149 | +) -> None: |
| 150 | + monkeypatch.setenv("MAGIC", "from-env") |
| 151 | + project = tox_project({filename: content}) |
| 152 | + outcome = project.run("c", "-e", "a", "-k", "commands", "-x", f"{namespace}.commands={override}", *posargs) |
| 153 | + outcome.assert_success() |
| 154 | + outcome.assert_out_err(f"[testenv:a]\ncommands = {expected}\n", "") |
0 commit comments