Skip to content

config: deprecate non-string values for string-typed ini options in ini mode - #14928

Closed
webdevsamran wants to merge 2 commits into
pytest-dev:mainfrom
webdevsamran:fix/ini-string-toml-list-deprecation
Closed

config: deprecate non-string values for string-typed ini options in ini mode#14928
webdevsamran wants to merge 2 commits into
pytest-dev:mainfrom
webdevsamran:fix/ini-string-toml-list-deprecation

Conversation

@webdevsamran

Copy link
Copy Markdown

Description

_getini_ini returned any value as-is for type="string" ini options (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 a string-typed option:

[tool.pytest.ini_options]
mystr = ["a", "b"]     # getini("mystr") == ['a', 'b'], silent

while the same array under [tool.pytest] raises TypeError. The strict side is new (native TOML work in 9.1); the lax return value dates 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:

  • ini mode + non-str value on a "string"-typed option → PytestDeprecationWarning now, TypeError in pytest 10.
  • make_scalar in findpaths.py is intentionally untouched: it keeps lists as lists so args/linelist/paths get their lists through; the decision belongs with the consumer that knows the declared type.

Changelog

changelog/14808.deprecation.rst added.

Testing

New test test_addini_string_type_toml_list_deprecated covers both an explicitly type="string" option and an untyped one:

testing/test_config.py::TestConfigAPI::test_addini_string_type_toml_list_deprecated PASSED

Full testing/test_config.py: 281 passed, 5 failed — the 5 failures reproduce identically on a clean checkout of main on this machine (Windows/Python 3.14 environment issues in TestConfigFromdictargs/TestOverrideIniArgs, unrelated to this change; verified via git stash).

Fixes #14808

…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.
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Aug 23, 2026
@RonnyPfannschmidt

Copy link
Copy Markdown
Member

Unattended ai dupe of preexisting pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_getini_ini: "string" type returns list silently instead of raising TypeError

2 participants