Skip to content

Commit 21ca67b

Browse files
committed
use python to get env
1 parent 047626d commit 21ca67b

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

tests/test_cli.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,28 +186,21 @@ def test_run(tmp_path):
186186
with pushd(tmp_path):
187187
(tmp_path / ".env").write_text("a=b")
188188

189-
# Use sys.executable to run the command via Python directly
190189
if IS_WINDOWS:
191-
# On Windows, use set command instead of echo with variable expansion
192-
printenv_cmd = [
193-
sys.executable,
194-
"-m",
195-
"dotenv",
196-
"run",
197-
"cmd",
198-
"/c",
199-
"set",
200-
"a",
201-
]
190+
# On Windows, use environment variables directly with the Python interpreter
191+
# Create a temporary batch file to source the environment and run Python
192+
batch_path = tmp_path / "run_test.bat"
193+
batch_path.write_text(
194+
f"@echo off\ndotenv run {sys.executable} -c \"import os; print(os.environ['a'])\""
195+
)
196+
197+
# Run the batch file directly
198+
result = run_command(f"{batch_path}")
202199
else:
203200
printenv_cmd = ["dotenv", "run", "printenv", "a"]
201+
result = run_command(printenv_cmd)
204202

205-
result = run_command(printenv_cmd)
206-
if IS_WINDOWS:
207-
# Windows 'set' command includes variable name, extract just the value
208-
assert result.strip().endswith("=b")
209-
else:
210-
assert result == "b\n"
203+
assert result.strip() == "b"
211204

212205

213206
def test_run_with_existing_variable(tmp_path):

0 commit comments

Comments
 (0)