♻️ refactor(plugin): consolidate TOML config parsing#193
Merged
gaborbernat merged 2 commits intopytest-dev:mainfrom Feb 11, 2026
Merged
♻️ refactor(plugin): consolidate TOML config parsing#193gaborbernat merged 2 commits intopytest-dev:mainfrom
gaborbernat merged 2 commits intopytest-dev:mainfrom
Conversation
The plugin was parsing TOML files twice during startup: once to extract env_files and again to load environment entries. This created ~40 lines of duplicate directory-walking logic and inconsistent error handling where TOMLDecodeError was silently swallowed when reading env_files but allowed to propagate when reading env entries. Consolidated into a single _load_toml_config() function that parses once and returns both env_files and entries. Added _find_toml_config() to handle discovery, checking early_config.inipath first before walking the tree. This maintains pytest-env's precedence model (TOML over INI) while avoiding redundant work. Also migrated test fixtures from deprecated testdir to modern pytester for future compatibility, and removed obsolete ANN101 lint rule from config.
Reordered functions to follow topological usage order with the main hook entrypoint at the top, making the code easier to read from top to bottom. Restored comments explaining the R:, D:, and U: flags in INI config parsing. These document the user-facing API and help explain why certain transformations happen, not just how the code works. Moved DOC201 and DOC402 linting rules to global ignore config instead of using per-function noqa comments, keeping the codebase cleaner.
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.
The plugin was parsing TOML configuration files twice during startup, leading to duplicate directory-walking logic and inconsistent error handling. When reading
env_files,TOMLDecodeErrorwas silently caught and ignored, but when reading environment entries from the same file, the error propagated normally. This created ~40 lines of redundant code and unpredictable behavior for malformed TOML files.♻️ Consolidated the parsing into a single
_load_toml_config()function that reads each TOML file once and returns bothenv_filesand entries. Added_find_toml_config()to handle discovery by checkingearly_config.inipathfirst (when it's a TOML file) before walking the directory tree. This maintains pytest-env's precedence model where TOML configs override INI configs, while eliminating the wasted I/O and parsing.The refactoring also migrated test fixtures from deprecated
testdirto modernpytesterfor future compatibility, and removed the obsoleteANN101lint rule from the config. All functionality remains unchanged from a user perspective—the improvements are purely internal optimization and bug fixes.