🐛 fix(config): use inipath for TOML file discovery#190
Merged
Conversation
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.
03d6719 to
c8e0da8
Compare
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.
When a subdirectory has its own
pytest.tomlwith[pytest_env], the parent'spyproject.tomlis incorrectly picked up first. This happens because the TOML file walk starts fromearly_config.rootpath, which always points to the project root regardless of which config file pytest actually resolved. 🔍 For example, running pytest fromtests_integration/with its ownpytest.tomlstill loads env vars from the rootpyproject.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'spytest.tomlwith[pytest_env]is found first, matching how pytest itself resolves configuration. WheninipathisNone(no config file found), the behavior falls back torootpath, 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