Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ Luke Murphy
Maciek Fijalkowski
Madan Kumar
Maggie Chung
Majid Al-Sakani
Maho
Maik Figura
Mandeep Bhutani
Expand Down
1 change: 1 addition & 0 deletions changelog/15290.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restore support for numeric strings in the ``verbosity_assertions``, ``verbosity_subtests``, and ``verbosity_test_cases`` TOML configuration options.
22 changes: 22 additions & 0 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,28 @@ def _getini(self, name: str):
mode, name, canonical_name, type, value, default
)

# Preserve support for numeric strings in fine-grained verbosity
# options while TOML's native integer values are handled directly.
if (
mode == "toml"
and isinstance(value, str)
and "int" in type
and canonical_name
in {
Config._verbosity_ini_name(Config.VERBOSITY_ASSERTIONS),
Config._verbosity_ini_name(Config.VERBOSITY_SUBTESTS),
Config._verbosity_ini_name(Config.VERBOSITY_TEST_CASES),
}
and any(
isinstance(member, _IniLiteral) and "auto" in member.choices
for member in type
)
):
try:
return int(value)
except ValueError:
pass

# Union: try each member; the first one that accepts the value wins.
for member in type:
try:
Expand Down
16 changes: 16 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3645,3 +3645,19 @@ def test_get_verbosity(self, pytester: Pytester) -> None:
pytester.maketoml("[pytest]\nverbosity_assertions = 2\n")
config = pytester.parseconfig()
assert config.get_verbosity(Config.VERBOSITY_ASSERTIONS) == 2

@pytest.mark.parametrize(
("name", "value", "expected"),
[
("verbosity_assertions", '"2"', 2),
("verbosity_subtests", '"-1"', -1),
("verbosity_test_cases", '"3"', 3),
],
)
def test_verbosity_accepts_numeric_strings_in_toml(
self, pytester: Pytester, name: str, value: str, expected: int
) -> None:
pytester.maketoml(f"[pytest]\n{name} = {value}\n")
config = pytester.parseconfig()
assert config.getini(name) == expected
assert config.get_verbosity(name.removeprefix("verbosity_")) == expected
Loading