Repository: pytest-dev/pytest
File: src/_pytest/reports.py (Python)

Code before:
            ________ Test.foo ________


        In the example above, the head_line is "Test.foo".

        .. note::

            This function is considered **experimental**, so beware that it is subject to changes
            even in patch releases.
        """
        if self.location is not None:
            fspath, lineno, domain = self.location
            return domain
        return None

    def _get_verbose_word_with_markup(
        self, config: Config, default_markup: Mapping[str, bool]
    ) -> tuple[str, Mapping[str, bool]]:
        _category, _short, verbose = config.hook.pytest_report_teststatus(
            report=self, config=config
        )

        if isinstance(verbose, str):
            return verbose, default_markup

        return verbose[0], verbose[1]

    def _to_json(self) -> dict[str, Any]:
        """Return the contents of this report as a dict of builtin entries,
        suitable for serialization.

        This was originally the serialize_report() function from xdist (ca03269).

        Experimental method.
        """
        return _report_to_json(self)

    @classmethod
    def _from_json(cls, reportdict: dict[str, object]) -> Self:
        """Create either a TestReport or CollectReport, depending on the calling class.

        It is the callers responsibility to know which class to pass here.

        This was originally the serialize_report() function from xdist (ca03269).

        Experimental method.
        """
        kwargs = _report_kwargs_from_json(reportdict)
        return cls(**kwargs)



Review comment (bug):
While at it, we should probably also verify that `verbose` is what we expect and raise an error otherwise:

```suggestion
        if isinstance(verbose, Sequence) and len(verbose) == 2:
            word, markup = verbose
            if isinstance(word, str) and isinstance(markup, Mapping):
                return word, markup
        pytest.fail("pytest_report_teststatus() hook (from a plugin) returned an invalid verbose value: {verbose!r}.\nExpected either a string or a tuple of (word, markup)."
```

Code after:
        failures::

            ________ Test.foo ________


        In the example above, the head_line is "Test.foo".

        .. note::

            This function is considered **experimental**, so beware that it is subject to changes
            even in patch releases.
        """
        if self.location is not None:
            fspath, lineno, domain = self.location
            return domain
        return None

    def _get_verbose_word_with_markup(
        self, config: Config, default_markup: Mapping[str, bool]
    ) -> tuple[str, Mapping[str, bool]]:
        _category, _short, verbose = config.hook.pytest_report_teststatus(
            report=self, config=config
        )

        if isinstance(verbose, str):
            return verbose, default_markup

        if isinstance(verbose, Sequence) and len(verbose) == 2:
            word, markup = verbose
            if isinstance(word, str) and isinstance(markup, Mapping):
                return word, markup

        fail(  # pragma: no cover
            "pytest_report_teststatus() hook (from a plugin) returned "
            f"an invalid verbose value: {verbose!r}.\nExpected either a string "
            "or a tuple of (word, markup)."
        )

    def _to_json(self) -> dict[str, Any]:
        """Return the contents of this report as a dict of builtin entries,
        suitable for serialization.

        This was originally the serialize_report() function from xdist (ca03269).

        Experimental method.
        """
        return _report_to_json(self)

    @classmethod
    def _from_json(cls, reportdict: dict[str, object]) -> Self:
        """Create either a TestReport or CollectReport, depending on the calling class.