|
1 | 1 | import os |
| 2 | +import sys |
2 | 3 | from pathlib import Path |
3 | 4 | from typing import Optional |
4 | 5 |
|
@@ -211,6 +212,40 @@ def test_run_with_existing_variable_not_overridden(tmp_path): |
211 | 212 | check_process(result, exit_code=0, stdout="C\n") |
212 | 213 |
|
213 | 214 |
|
| 215 | +@pytest.mark.parametrize( |
| 216 | + "option,existing_value,expected", |
| 217 | + [ |
| 218 | + ("--override", "environment", "file\nfile/suffix\n"), |
| 219 | + ("--no-override", "environment", "environment\nenvironment/suffix\n"), |
| 220 | + ("--no-override", "", "\n/suffix\n"), |
| 221 | + ], |
| 222 | +) |
| 223 | +def test_run_interpolation_respects_override( |
| 224 | + tmp_path, option, existing_value, expected |
| 225 | +): |
| 226 | + (tmp_path / ".env").write_text( |
| 227 | + "DOTENV_TEST_BASE=file\nDOTENV_TEST_DERIVED=${DOTENV_TEST_BASE}/suffix\n" |
| 228 | + ) |
| 229 | + env = dict(os.environ) |
| 230 | + env.pop("DOTENV_TEST_DERIVED", None) |
| 231 | + env["DOTENV_TEST_BASE"] = existing_value |
| 232 | + |
| 233 | + result = run_dotenv( |
| 234 | + [ |
| 235 | + "run", |
| 236 | + option, |
| 237 | + sys.executable, |
| 238 | + "-c", |
| 239 | + "import os; print(os.environ['DOTENV_TEST_BASE']); " |
| 240 | + "print(os.environ['DOTENV_TEST_DERIVED'])", |
| 241 | + ], |
| 242 | + cwd=tmp_path, |
| 243 | + env=env, |
| 244 | + ) |
| 245 | + |
| 246 | + check_process(result, exit_code=0, stdout=expected) |
| 247 | + |
| 248 | + |
214 | 249 | def test_run_with_none_value(tmp_path): |
215 | 250 | (tmp_path / ".env").write_text("A=x\nc") |
216 | 251 |
|
|
0 commit comments