Repository navigation
🐛 fix(config): read pytest_env from a custom -c file - #339
Merged
Merged
Conversation
pytest accepts a TOML file with any name through -c, and pytest-env ignored the [pytest_env] table in it because it only accepted three file names for the selected configuration. A sibling or parent file's table was applied in its place, so a run with a separate CI configuration used the developer variables. Reported by Anthropic's OSS Scanner: ANT-2026-0WEHVFMQ. Fixes pytest-dev#326
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.
_find_toml_configaccepted the configuration file pytest selected only when it was namedpytest.toml,.pytest.tomlorpyproject.toml(old lines). Withpytest -c ci.toml, pytest-env ignored the[pytest_env]table inci.tomland applied the table of a sibling or parent file, or nothing. A project with a separate CI configuration ran its tests with the developer variables, and the run passed. 🐛 After this PR the selected file's table applies. Fixes #326.The selected file was not opened
pytest takes a TOML file with any name through
-c, and since 9.2 reads[pytest]from it like it does forpytest.toml. For a name outside the three, pytest-env went straight to the walk, which looks for the three fixed names in the file's directory and its parents.env_filesandenv_files_skip_if_setcome from the same lookup, so those keys in the ignored table had no effect either. The first check now accepts any selected file with a.tomlsuffix that holds the table.Behavior changes
A TOML file selected with
-cunder another name is read likepytest.toml: its top-level[pytest_env]table supplies the entries,env_filesandenv_files_skip_if_set, and it wins over sibling and parent files. A run that passed such a file and got its variables from a siblingpyproject.tomlnow gets them from the selected file. A selected file without the table falls back to the walk as before. A custom-named file that uses thepyproject.tomllayout,[tool.pytest_env], is still not read. The walk still looks only for the three fixed names. The README and the threat model describe the selected file.Reported by Anthropic's OSS Scanner: ANT-2026-0WEHVFMQ.