From 9fa6fd91d910c7fbced9012505693dfd8b96c4e4 Mon Sep 17 00:00:00 2001 From: ANSHUL SINGH <72524975+ekanshul@users.noreply.github.com> Date: Tue, 29 Sep 2026 17:38:03 +0000 Subject: [PATCH 1/2] Fix test_run_with_command_flags on macOS BSD printenv The test used printenv --version to check that dotenv run forwards flags. GNU printenv accepts that flag; BSD printenv on macOS does not, so the suite fails even though flag forwarding works. Use the current Python interpreter's --version instead. Fixes #708 --- tests/test_cli.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index d4e3ad4d..00304e7e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,4 +1,5 @@ import os +import sys from pathlib import Path from typing import Optional @@ -269,16 +270,18 @@ def test_run_with_command_flags(dotenv_path, tmp_path): """ Check that command flags passed after `dotenv run` are not interpreted. - Here, we want to run `printenv --version`, not `dotenv --version`. + Use the current interpreter's ``--version`` so this stays portable: GNU + printenv accepts ``--version``, but BSD printenv (macOS) does not. """ result = run_dotenv( - ["--file", str(dotenv_path), "run", "printenv", "--version"], + ["--file", str(dotenv_path), "run", sys.executable, "--version"], cwd=tmp_path, ) check_process(result, exit_code=0) - assert result.stdout.strip().startswith("printenv ") + combined = (result.stdout + result.stderr).strip() + assert combined.startswith("Python ") def test_run_with_dotenv_and_command_flags(dotenv_path, tmp_path): From e260e63a28bbfceadde4c82f28813e8cf555a7aa Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Wed, 30 Sep 2026 09:01:40 +0530 Subject: [PATCH 2/2] test: check that dotenv run forwards a flag it defines itself `dotenv run` has no `--version` option, so the pre-#607 code forwarded it too and the test couldn't catch a regression. Forward `--help` instead, which `run` would otherwise handle, and assert the exact argv the command receives. --- tests/test_cli.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 00304e7e..7bcffbab 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -270,18 +270,24 @@ def test_run_with_command_flags(dotenv_path, tmp_path): """ Check that command flags passed after `dotenv run` are not interpreted. - Use the current interpreter's ``--version`` so this stays portable: GNU - printenv accepts ``--version``, but BSD printenv (macOS) does not. + Here, we want the command to receive `--help`, not `dotenv run --help`. + `sys.executable` is used instead of a system tool for portability. """ result = run_dotenv( - ["--file", str(dotenv_path), "run", sys.executable, "--version"], + [ + "--file", + str(dotenv_path), + "run", + sys.executable, + "-c", + "import sys; print(sys.argv[1:])", + "--help", + ], cwd=tmp_path, ) - check_process(result, exit_code=0) - combined = (result.stdout + result.stderr).strip() - assert combined.startswith("Python ") + check_process(result, exit_code=0, stdout="['--help']\n") def test_run_with_dotenv_and_command_flags(dotenv_path, tmp_path):