Skip to content
Closed
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 @@ -292,6 +292,7 @@ Liam DeVoe
Llandy Riveron Del Risco
Loic Esteve
lovetheguitar
Lpk124
Luana Pinho Bueno Penha
Lukas Bednar
Luke Murphy
Expand Down
3 changes: 3 additions & 0 deletions changelog/15290.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TOML configuration again accepts numeric strings for the
:confval:`verbosity_assertions`, :confval:`verbosity_subtests`, and
:confval:`verbosity_test_cases` options.
21 changes: 20 additions & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1957,10 +1957,29 @@ def _getini(self, name: str):
)

# Union: try each member; the first one that accepts the value wins.
coerce_toml_int_strings = name in {
Config._verbosity_ini_name(Config.VERBOSITY_ASSERTIONS),
Config._verbosity_ini_name(Config.VERBOSITY_SUBTESTS),
Config._verbosity_ini_name(Config.VERBOSITY_TEST_CASES),
}
for member in type:
try:
# Keep accepting numeric strings for built-in verbosity options.
member_value = (
int(value)
if mode == "toml"
and member == "int"
and isinstance(value, str)
and coerce_toml_int_strings
else value
)
return self._getini_value(
mode, name, canonical_name, member, value, default
mode,
name,
canonical_name,
member,
member_value,
default,
)
except (TypeError, ValueError):
pass
Expand Down
8 changes: 6 additions & 2 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3599,8 +3599,11 @@ class TestNativeTomlOptionTypes:
("name", "toml_value", "ini_value", "expected"),
[
("verbosity_assertions", "2", "2", 2),
("verbosity_assertions", '"2"', "2", 2),
("verbosity_assertions", '"auto"', "auto", "auto"),
("verbosity_subtests", '"1"', "1", 1),
("verbosity_test_cases", "-1", "-1", -1),
("verbosity_test_cases", '"-1"', "-1", -1),
("tmp_path_retention_count", "0", "0", 0),
("log_level", "10", "10", 10),
("log_level", '"INFO"', "INFO", "INFO"),
Expand Down Expand Up @@ -3641,7 +3644,8 @@ def test_invalid_value(self, pytester: Pytester, name: str, value: str) -> None:
with pytest.raises(UsageError, match=name):
config.getini(name)

def test_get_verbosity(self, pytester: Pytester) -> None:
pytester.maketoml("[pytest]\nverbosity_assertions = 2\n")
@pytest.mark.parametrize("toml_value", ["2", '"2"'])
def test_get_verbosity(self, pytester: Pytester, toml_value: str) -> None:
pytester.maketoml(f"[pytest]\nverbosity_assertions = {toml_value}\n")
config = pytester.parseconfig()
assert config.get_verbosity(Config.VERBOSITY_ASSERTIONS) == 2
Loading