test_run_with_command_flags fails on macOS (BSD printenv doesn't support --version)
还没有人认领这个 Issue。
评估
调研方向
从 tests/test_cli.py::test_run_with_command_flags 开始,检查它如何调用 dotenv run printenv --version。将特定于操作系统的 sentinel 替换为建议的输出 argv 的 Python 命令,然后在 macOS 上使用 pytest 或 tox 运行此测试,并确认 flag 转发断言通过。
由索引模型根据 Issue 内容生成。
描述
Description
tests/test_cli.py::test_run_with_command_flags fails when running the test suite (via tox or pytest) on macOS.
tests/test_cli.py::test_run_with_command_flags FAILED
AssertionError: Unexpected exit code 1 (expected 0)
stdout:
stderr:
printenv: illegal option -- -
usage: printenv [name]
assert 1 == 0
Root cause
The test runs dotenv run printenv --version and asserts it exits 0, to verify that dotenv run forwards flags to the wrapped command instead of parsing them itself (added in #607 / #612).
- On Linux,
printenvis GNU coreutils' version, which supports--versionand exits 0. - On macOS,
printenvis the BSD version, which does not support--versionat all, and exits 1 withprintenv: illegal option -- -.
So the test is actually working as intended (dotenv run correctly passes --version straight through to printenv rather than swallowing it), but the assertion only holds on systems with GNU printenv.
Why this hasn't been caught in CI
.github/workflows/test.yml only runs the test matrix on ubuntu-latest and windows-latest - there's no macos-latest job, so this has never surfaced there.
CONTRIBUTING.md tells contributors to just run tox or pytest, with no mention that the suite assumes a GNU userland / Linux, so a macOS contributor following the documented steps hits this with no explanation.
Suggested fix
Replace the OS-specific sentinel command (printenv --version) with something that behaves identically across GNU/BSD/Windows, e.g. a small python -c "..." snippet that just echoes its argv, so the test only cares about flag-forwarding behavior rather than a specific external tool's flag parsing.
Environment
- macOS (Darwin), tested via
toxlocally - Reproducible with plain
pytesttoo, since it's just calling the systemprintenv
- 主要语言
- Python
- 星标
- 8.9k
- 派生
- 585
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
theskumar/python-dotenv 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
theskumar/python-dotenv#699 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 35/100
theskumar/python-dotenv#697 ·
-
难度 5/5 一周以上 新手友好度 28/100
theskumar/python-dotenv#693 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 55/100
theskumar/python-dotenv#683 · 4 条评论 ·
-
难度 3/5 1-2 天 新手友好度 55/100
theskumar/python-dotenv#644 · 2 条评论 ·
查看 theskumar/python-dotenv 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
PedestrianDynamics/pyFDS-Evac#343 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 2 天内回复
-
Docs Timedelta
难度 2/5 1-3 小时 新手友好度 72/100
pandas-dev/pandas#69919 ·
维护者通常 1 天内回复
-
API documentation
难度 2/5 1-3 小时 新手友好度 72/100
zephyrproject-rtos/west#1009 · 2 条评论 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
pgadmin-org/pgadmin4#10474 ·
维护者通常 4 天内回复