diff --git a/src/_pytest/reports.py b/src/_pytest/reports.py index c85bf78594f..480ffae1f9c 100644 --- a/src/_pytest/reports.py +++ b/src/_pytest/reports.py @@ -261,8 +261,6 @@ class TestReport(BaseReport): __test__ = False - when: Literal["setup", "call", "teardown"] - location: tuple[str, int | None, str] # Defined by skipping plugin. # xfail reason if xfailed, otherwise not defined. Use hasattr to distinguish. wasxfail: str @@ -307,7 +305,7 @@ def __init__( self.longrepr = longrepr #: One of 'setup', 'call', 'teardown' to indicate runtest phase. - self.when = when + self.when: Literal["setup", "call", "teardown"] = when #: User properties is a list of tuples (name, value) that holds user #: defined properties of the test. diff --git a/testing/typing_checks.py b/testing/typing_checks.py index d4d6a97aea6..8a316580a25 100644 --- a/testing/typing_checks.py +++ b/testing/typing_checks.py @@ -8,12 +8,14 @@ from __future__ import annotations import contextlib +from typing import Literal from typing import Optional from typing_extensions import assert_type import pytest from pytest import MonkeyPatch +from pytest import TestReport # Issue #7488. @@ -51,3 +53,9 @@ def check_raises_is_a_context_manager(val: bool) -> None: with pytest.raises(RuntimeError) if val else contextlib.nullcontext() as excinfo: pass assert_type(excinfo, Optional[pytest.ExceptionInfo[RuntimeError]]) + + +# Issue #12941. +def check_testreport_attributes(report: TestReport) -> None: + assert_type(report.when, Literal["setup", "call", "teardown"]) + assert_type(report.location, tuple[str, Optional[int], str])