Skip to content
Merged
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
4 changes: 1 addition & 3 deletions src/_pytest/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions testing/typing_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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])