Skip to content

fix config: add deprecation warning for non-string value in string-typed ini option - #14811

Merged
RonnyPfannschmidt merged 1 commit into
pytest-dev:mainfrom
EternalRights:fix-config-getini-string-validation
Aug 25, 2026
Merged

RonnyPfannschmidt merged 1 commit into
pytest-dev:mainfrom
EternalRights:fix-config-getini-string-validation

Conversation

@EternalRights

Copy link
Copy Markdown
Contributor

Ran into this while comparing _getini_toml and _getini_ini. The former validates with isinstance(value, str) for type="string", but _getini_ini just returns the value as-is. In [tool.pytest.ini_options], make_scalar keeps TOML arrays as lists, so a list reaches _getini_ini and gets returned without any warning. "int" and "float" types in _getini_ini already have the guard. "string" is the only scalar type missing it.

As Ronny pointed out, this needs a deprecation path rather than raising immediately, since addini(type=None) normalizes to "string" and many plugins rely on the implicit default.

The fix adds a PytestRemovedIn10Warning when _getini_ini sees a non-str value on a string-typed option. The value is still returned for backward compatibility. In pytest 10 this will become a TypeError, matching the _getini_toml path.

Closes #14808

…ped ini option

_getini_ini returns the value as-is for type="string", unlike _getini_toml
which validates with isinstance(value, str). In [tool.pytest.ini_options],
make_scalar keeps TOML arrays as lists, so a list value reaches _getini_ini
and gets returned without warning. "int" and "float" types already have the
guard.

Add a PytestRemovedIn10Warning for non-str values in _getini_ini's string
branch. The value is still returned for now; in pytest 10 this will raise
TypeError, matching _getini_toml.

Closes pytest-dev#14808
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jul 31, 2026
@RonnyPfannschmidt
RonnyPfannschmidt merged commit 9775753 into pytest-dev:main Aug 25, 2026
36 checks passed
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