Repository navigation
🐛 fix(envfile): reject an empty --envfile value - #330
Merged
Merged
Conversation
`pytest --envfile "$CI_ENV_FILE"` with the variable unset passed an empty string, which the truthiness test took for a missing option. The run loaded the configured env files and could pass, where the README promises FileNotFoundError for a CLI file that does not exist. Reported by Anthropic's OSS Scanner: ANT-2026-N9HYJG69. Fixes pytest-dev#320
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_load_env_filesdecided whether--envfilewas passed by testing the option's truthiness (old line).pytest --envfile "", which is whatpytest --envfile "$CI_ENV_FILE"runs when the variable is unset, was therefore handled like a run without the option: pytest loaded the configuredenv_filesand could exit 0. 🐛 After this PR an empty value raisesFileNotFoundError, as the README documents for a CLI file that does not exist. Fixes #320.The empty value was treated as a missing option
The option defaults to
None, and argparse stores an empty string for--envfile "". Both are falsy, so the function yielded the configured files and returned before the existence check._load_env_filesnow compares the option withNone, so the empty name reaches that check, where the rootdir joined with an empty name is a directory and not a file.Behavior changes
pytest --envfile ""andpytest --envfile=stop withFileNotFoundError: Environment file not found:before collection. A script that relied on an empty value to fall back to the configured files has to drop the option instead. Runs without--envfileand runs with a non-empty value behave as before.Reported by Anthropic's OSS Scanner: ANT-2026-N9HYJG69.