Skip to content

verbosity_assertions needs a string in TOML, docs show int #13904

Description

@nedbat

Using 8.4.2 I had this in pyproject.toml:

[tool.pytest.ini_options]
verbosity_assertions = 5

With 9.0.0, I changed to:

[tool.pytest]
verbosity_assertions = 5

But 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"

Activity

  1. bluetech commented on Nov 9, 2025

    @bluetech
    Member

    Thanks, we'll fix it.

  2. added theissue type on Nov 9, 2025
  3. added
    type: docsdocumentation improvement, missing or needing clarification
    topic: configrelated to config handling, argument parsing and config file
    type: regressionindicates a problem that was introduced in a release which was working previously
    and removed
    type: regressionindicates a problem that was introduced in a release which was working previously
    on Nov 9, 2025
  4. added 2 commits that reference this issue on Nov 9, 2025
    1865168
    500146b
  5. remimd commented on Nov 12, 2025

    @remimd

    Same issue for tmp_path_retention_count

  6. bluetech commented on Nov 13, 2025

    @bluetech
    Member

    Thanks for the report @remimd.

    This one looks like a mistake, in this case there is no reason for it to be an string rather than an int.

    I wonder if we can still fix it (change to int) or if it's too late. Maybe it's possible to make both int and str work using some hack. I will check.

  7. added a commit that references this issue on Nov 13, 2025
    2e34924
  8. added a commit that references this issue on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: configrelated to config handling, argument parsing and config filetype: docsdocumentation improvement, missing or needing clarification

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions