Skip to content

🐛 fix(config): use inipath for TOML file discovery#190

Merged
gaborbernat merged 2 commits into
pytest-dev:mainfrom
gaborbernat:75
Feb 11, 2026
Merged

🐛 fix(config): use inipath for TOML file discovery#190
gaborbernat merged 2 commits into
pytest-dev:mainfrom
gaborbernat:75

Conversation

@gaborbernat
Copy link
Copy Markdown
Collaborator

@gaborbernat gaborbernat commented Feb 11, 2026

When a subdirectory has its own pytest.toml with [pytest_env], the parent's pyproject.toml is incorrectly picked up first. This happens because the TOML file walk starts from early_config.rootpath, which always points to the project root regardless of which config file pytest actually resolved. 🔍 For example, running pytest from tests_integration/ with its own pytest.toml still loads env vars from the root pyproject.toml.

The fix changes the walk starting point to early_config.inipath.parent — the directory containing the config file pytest resolved. This way a subdirectory's pytest.toml with [pytest_env] is found first, matching how pytest itself resolves configuration. When inipath is None (no config file found), the behavior falls back to rootpath, preserving existing behavior.

📝 The README has also been restructured for clarity: TOML and INI configuration are now separate sections with reference tables for inline-table keys and prefix flags, precedence rules and file discovery are documented explicitly, and feature examples are consolidated with side-by-side TOML/INI comparisons.

Fixes #75

@gaborbernat gaborbernat changed the title Fix TOML config walk starting from inipath 🐛 fix(config): start TOML walk from inipath Feb 11, 2026
When pytest resolves config to a subdirectory (e.g. tests_integration/pytest.toml),
rootpath still points to the project root. This caused the parent pyproject.toml
to be found first, ignoring the subdirectory's pytest_env config.

Starting from inipath.parent ensures the walk begins at the directory of the
resolved config file, finding the correct pytest_env section. Falls back to
rootpath when no config file is found.
@gaborbernat gaborbernat force-pushed the 75 branch 2 times, most recently from 03d6719 to c8e0da8 Compare February 11, 2026 16:08
@gaborbernat gaborbernat changed the title 🐛 fix(config): start TOML walk from inipath 🐛 fix(config): use inipath for TOML file discovery Feb 11, 2026
@gaborbernat gaborbernat merged commit 9e52830 into pytest-dev:main Feb 11, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Override native toml ([tool.pytest_env]) with (pytest.ini) configuration in sub dir

1 participant