Skip to content

🐛 fix(config): read pytest_env from a custom -c file - #339

Merged
gaborbernat merged 1 commit into
pytest-dev:mainfrom
gaborbernat:fix/custom-toml-name
Nov 17, 2026
Merged

gaborbernat merged 1 commit into
pytest-dev:mainfrom
gaborbernat:fix/custom-toml-name

Conversation

@gaborbernat

Copy link
Copy Markdown
Collaborator

_find_toml_config accepted the configuration file pytest selected only when it was named pytest.toml, .pytest.toml or pyproject.toml (old lines). With pytest -c ci.toml, pytest-env ignored the [pytest_env] table in ci.toml and 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 for pytest.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_files and env_files_skip_if_set come 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 .toml suffix that holds the table.

Behavior changes

A TOML file selected with -c under another name is read like pytest.toml: its top-level [pytest_env] table supplies the entries, env_files and env_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 sibling pyproject.toml now 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 the pyproject.toml layout, [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.

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
@gaborbernat gaborbernat added the bug Something isn't working label Nov 17, 2026
@gaborbernat
gaborbernat merged commit 8a1bbd1 into pytest-dev:main Nov 17, 2026
20 checks passed
@gaborbernat
gaborbernat deleted the fix/custom-toml-name branch November 17, 2026 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pytest_env] in a custom-named TOML file passed with -c is ignored

1 participant