-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Labels
topic: configrelated to config handling, argument parsing and config filerelated to config handling, argument parsing and config filetype: docsdocumentation improvement, missing or needing clarificationdocumentation improvement, missing or needing clarification
Description
Using 8.4.2 I had this in pyproject.toml:
[tool.pytest.ini_options]
verbosity_assertions = 5With 9.0.0, I changed to:
[tool.pytest]
verbosity_assertions = 5But this causes an error:
self = <_pytest.config.Config object at 0x104f63220>, name = 'verbosity_assertions', canonical_name = 'verbosity_assertions', type = 'string', value = 5
default = 'auto'
def _getini_toml(
self,
name: str,
canonical_name: str,
type: str,
value: object,
default: Any,
):
"""Handle TOML config values with strict type validation and no coercion.
In TOML mode, values already have native types from TOML parsing.
We validate types match expectations exactly, including list items.
"""
value_type = builtins.type(value).__name__
if type == "paths":
# Expect a list of strings.
if not isinstance(value, list):
raise TypeError(
f"{self.inipath}: config option '{name}' expects a list for type 'paths', "
f"got {value_type}: {value!r}"
)
for i, item in enumerate(value):
if not isinstance(item, str):
item_type = builtins.type(item).__name__
raise TypeError(
f"{self.inipath}: config option '{name}' expects a list of strings, "
f"but item at index {i} is {item_type}: {item!r}"
)
dp = (
self.inipath.parent
if self.inipath is not None
else self.invocation_params.dir
)
return [dp / x for x in value]
elif type in {"args", "linelist"}:
# Expect a list of strings.
if not isinstance(value, list):
raise TypeError(
f"{self.inipath}: config option '{name}' expects a list for type '{type}', "
f"got {value_type}: {value!r}"
)
for i, item in enumerate(value):
if not isinstance(item, str):
item_type = builtins.type(item).__name__
raise TypeError(
f"{self.inipath}: config option '{name}' expects a list of strings, "
f"but item at index {i} is {item_type}: {item!r}"
)
return list(value)
elif type == "bool":
# Expect a boolean.
if not isinstance(value, bool):
raise TypeError(
f"{self.inipath}: config option '{name}' expects a bool, "
f"got {value_type}: {value!r}"
)
return value
elif type == "int":
# Expect an integer (but not bool, which is a subclass of int).
if not isinstance(value, int) or isinstance(value, bool):
raise TypeError(
f"{self.inipath}: config option '{name}' expects an int, "
f"got {value_type}: {value!r}"
)
return value
elif type == "float":
# Expect a float or integer only.
if not isinstance(value, (float, int)) or isinstance(value, bool):
raise TypeError(
f"{self.inipath}: config option '{name}' expects a float, "
f"got {value_type}: {value!r}"
)
return value
elif type == "string":
# Expect a string.
if not isinstance(value, str):
> raise TypeError(
f"{self.inipath}: config option '{name}' expects a string, "
f"got {value_type}: {value!r}"
)
E TypeError: /Users/ned/coverage/trunk/pyproject.toml: config option 'verbosity_assertions' expects a string, got int: 5
/usr/local/virtualenvs/coverage/lib/python3.10/site-packages/_pytest/config/__init__.py:1816: TypeError
This fixes it, but the docs say it should be an int:
[tool.pytest]
verbosity_assertions = "5"Metadata
Metadata
Assignees
Labels
topic: configrelated to config handling, argument parsing and config filerelated to config handling, argument parsing and config filetype: docsdocumentation improvement, missing or needing clarificationdocumentation improvement, missing or needing clarification