Skip to content

Fix test_run_with_command_flags on macOS (BSD printenv) - #709

Merged
theskumar merged 2 commits into
theskumar:mainfrom
ekanshul:fix/cli-run-macos-printenv-version
Sep 30, 2026
Merged

theskumar merged 2 commits into
theskumar:mainfrom
ekanshul:fix/cli-run-macos-printenv-version

Conversation

@ekanshul

Copy link
Copy Markdown

Fixes #708.

test_run_with_command_flags ran printenv --version to prove that dotenv run forwards flags instead of swallowing them. That only works with GNU printenv. On macOS, BSD printenv rejects --version (illegal option -- -) and the test fails even though forwarding is correct.

This switches the sentinel command to sys.executable --version, which behaves the same on Linux, macOS, and Windows.

ekanshul and others added 2 commits September 29, 2026 17:38
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 theskumar#708
`dotenv run` has no `--version` option, so the pre-theskumar#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.
@theskumar

Copy link
Copy Markdown
Owner

Thanks @ekanshul, the switch to sys.executable fixes the macOS failure. I checked it with a BSD-style printenv shim: main fails this test, and this branch passes the full suite.

While reviewing, I noticed the test couldn't catch the regression it was written for (#607). dotenv run has no --version option, so the pre-#607 code forwarded --version too. I've pushed a follow-up commit (e260e63) on top of yours that forwards --help (which run does define) and asserts the exact argv the command receives:

check_process(result, exit_code=0, stdout="['--help']\n")

Mutation results for test_run_with_command_flags (mutants applied to src/dotenv/cli.py):

Mutant python --version --help + argv (new)
pre-#607 run (only ignore_unknown_options) missed caught
allow_interspersed_args=True missed caught
forward only argv[0] caught caught

This also drops the stdout + stderr fallback: python --version writes to stdout on Python 3, and the new assertion is an exact stdout match.

@theskumar
theskumar merged commit 58f2d7c into theskumar:main Sep 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_run_with_command_flags fails on macOS (BSD printenv doesn't support --version)

2 participants