Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#708 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
cli, testing

调研方向

从 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, printenv is GNU coreutils' version, which supports --version and exits 0.
  • On macOS, printenv is the BSD version, which does not support --version at all, and exits 1 with printenv: 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 tox locally
  • Reproducible with plain pytest too, since it's just calling the system printenv
主要语言
Python
星标
8.9k
派生
585
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

theskumar/python-dotenv 的其他 Issue

查看 theskumar/python-dotenv 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。