Skip to content

♻️ refactor(plugin): consolidate TOML config parsing#193

Merged
gaborbernat merged 2 commits intopytest-dev:mainfrom
gaborbernat:184
Feb 11, 2026
Merged

♻️ refactor(plugin): consolidate TOML config parsing#193
gaborbernat merged 2 commits intopytest-dev:mainfrom
gaborbernat:184

Conversation

@gaborbernat
Copy link
Collaborator

The plugin was parsing TOML configuration files twice during startup, leading to duplicate directory-walking logic and inconsistent error handling. When reading env_files, TOMLDecodeError was 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 both env_files and entries. Added _find_toml_config() to handle discovery by checking early_config.inipath first (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 testdir to modern pytester for future compatibility, and removed the obsolete ANN101 lint rule from the config. All functionality remains unchanged from a user perspective—the improvements are purely internal optimization and bug fixes.

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.
@gaborbernat gaborbernat merged commit 16158a4 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.

1 participant