Repository navigation
🐛 fix(config): name the TOML file that fails to parse - #333
Merged
Merged
Conversation
Discovery parses every pytest.toml, .pytest.toml and pyproject.toml between the configuration directory and the filesystem root. A half-written file in a parent directory stopped every run below it with a bare TOMLDecodeError that gave a line and column and no path. A `tool` or `pytest_env` value that is not a table was taken for a section and crashed later with AttributeError or TypeError. Reported by Anthropic's OSS Scanner: ANT-2026-ZUBFXUVY. Fixes pytest-dev#325
# Conflicts: # README.md # tests/test_env.py
# Conflicts: # README.md
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.
_has_env_sectionparsed everypytest.toml,.pytest.tomlandpyproject.tomlthat discovery handed it with an unguardedtomllib.load, and tested"pytest_env" in configwithout checking types (old lines). A file that did not parse, in any directory above a project, stopped every run below it with a traceback that gave a line and a column and no path, even when the project did not use pytest-env. 🐛 After this PR the error names the file, and atoolorpytest_envvalue that is not a table no longer counts as a section. Fixes #325.The parse error carried no path
_find_toml_configwalks from the configuration directory to the filesystem root, so it reads files pytest's own search does not reach once pytest has found the project's configuration.tomllib.TOMLDecodeErrorholds a position and no file name, and nothing caught it._has_env_sectionnow catchesTOMLDecodeErrorandUnicodeDecodeErrorand raisespytest.UsageErrorwith the path in front of the message, the format pytest uses for its own configuration files.A non-table value was taken for a section
"pytest_env" in configis a substring test whenconfigis a string. Apyproject.tomlwithtool = "notes: try pytest_env later"was selected as the configuration and failed in_load_toml_configwithAttributeError: 'str' object has no attribute 'get';tool = 1raisedTypeError. The function now reports a section only when it is a table, and forpyproject.tomlonly whentoolis a table too. An explicit empty table still counts and still stops discovery.Behavior changes
A TOML file on the discovery path that does not parse stops pytest with
ERROR: <path>: <parser message>and exit code 4, where it used to end in a traceback. The run still stops: pytest-env does not skip a broken file. A file whosepytest_envortoolis not a table is passed over and discovery continues to the next candidate.Reported by Anthropic's OSS Scanner: ANT-2026-ZUBFXUVY.