You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
INI env lines with unknown flags or no = are applied instead of rejected #323
A mistyped line in the INI env option is applied as a different instruction, and pytest exits 0 without a warning. DR:API_TOKEN=local-default overwrites an existing API_TOKEN, because DR is not read as D plus R. DB_HOST: test-db leaves DB_HOST alone and creates an empty variable named test-db.
The parser splits the text before the first = on :, takes the last piece as the name and every earlier piece as a flag. It looks the flags up only by asking whether R, D or U is among them, so a piece that is none of the three is dropped and the entry is applied as if it carried no flag. A line without = goes through the same split: for DB_HOST: test-db, DB_HOST becomes a flag, test-db the name, and the value is empty.
Reproduction
repro.sh
cd"$(mktemp -d)"printf'[pytest]\nenv =\n DB_HOST: test-db\n DR:API_TOKEN=local-default\n'> pytest.ini
cat > test_env.py <<'PY'import osdef test_env() -> None: print({name: os.environ.get(name) for name in ("DB_HOST", "test-db", "API_TOKEN")})PY
DB_HOST=prod-db API_TOKEN=ci-token pytest -q -s
Run with sh repro.sh at 3ebb6b4872fd0e450b6670d529e375e11c218e61, with pytest 9.2.0, python-dotenv 1.2.4 and CPython 3.14 on Linux:
Expected: pytest stops with a usage error that names the malformed line.
Impact
A typo in a flag turns a default into an overwrite, or sets a variable other than the one the line was written for, and the run gives no sign of it. The native [pytest_env] tables use a separate parser and are not affected.
Reproducibility: easy. One command with default options.
Real-world exposure: niche. It needs a line outside the documented (FLAG:)NAME=VALUE form.
Credits
Reported by Anthropic's OSS Scanner: ANT-2026-4L02Y0M6.
Activity