config: deprecate non-string values for string-typed ini options in ini mode - #14928
Closed
webdevsamran wants to merge 2 commits into
Closed
config: deprecate non-string values for string-typed ini options in ini mode#14928webdevsamran wants to merge 2 commits into
webdevsamran wants to merge 2 commits into
Conversation
…ni mode _getini_ini returned any value as-is for type='string' (the default when addini is called without type=), while _getini_toml strictly validates. A TOML array in [tool.pytest.ini_options] therefore silently became a list for string-typed options. Per the maintainer-approved path in pytest-dev#14808, emit a PytestDeprecationWarning in ini mode when a string-typed option receives a non-str value; it will raise TypeError in pytest 10.
for more information, see https://pre-commit.ci
Member
|
Unattended ai dupe of preexisting pr |
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.
Description
_getini_inireturned any value as-is fortype="string"ini options (the default whenaddini()is called withouttype=), while_getini_tomlstrictly validates. A TOML array in[tool.pytest.ini_options]therefore silently became alistfor a string-typed option:while the same array under
[tool.pytest]raisesTypeError. The strict side is new (native TOML work in 9.1); the laxreturn valuedates to 2010.Approach
As suggested by @RonnyPfannschmidt in #14808, this takes the deprecation path rather than an immediate hard error, because every untyped plugin option is string-typed and some may (deliberately or not) accept list shapes today:
strvalue on a"string"-typed option →PytestDeprecationWarningnow,TypeErrorin pytest 10.make_scalarinfindpaths.pyis intentionally untouched: it keeps lists as lists soargs/linelist/pathsget their lists through; the decision belongs with the consumer that knows the declared type.Changelog
changelog/14808.deprecation.rstadded.Testing
New test
test_addini_string_type_toml_list_deprecatedcovers both an explicitlytype="string"option and an untyped one:Full
testing/test_config.py: 281 passed, 5 failed — the 5 failures reproduce identically on a clean checkout ofmainon this machine (Windows/Python 3.14 environment issues inTestConfigFromdictargs/TestOverrideIniArgs, unrelated to this change; verified viagit stash).Fixes #14808