Skip to content

Commit 636d956

Browse files
authored
Clean up type hints and add a test (#13348)
Based on discussion in #13345.
1 parent 4056433 commit 636d956

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/_pytest/reports.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,6 @@ class TestReport(BaseReport):
261261

262262
__test__ = False
263263

264-
when: Literal["setup", "call", "teardown"]
265-
location: tuple[str, int | None, str]
266264
# Defined by skipping plugin.
267265
# xfail reason if xfailed, otherwise not defined. Use hasattr to distinguish.
268266
wasxfail: str
@@ -307,7 +305,7 @@ def __init__(
307305
self.longrepr = longrepr
308306

309307
#: One of 'setup', 'call', 'teardown' to indicate runtest phase.
310-
self.when = when
308+
self.when: Literal["setup", "call", "teardown"] = when
311309

312310
#: User properties is a list of tuples (name, value) that holds user
313311
#: defined properties of the test.

testing/typing_checks.py

+8
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
from __future__ import annotations
99

1010
import contextlib
11+
from typing import Literal
1112
from typing import Optional
1213

1314
from typing_extensions import assert_type
1415

1516
import pytest
1617
from pytest import MonkeyPatch
18+
from pytest import TestReport
1719

1820

1921
# Issue #7488.
@@ -51,3 +53,9 @@ def check_raises_is_a_context_manager(val: bool) -> None:
5153
with pytest.raises(RuntimeError) if val else contextlib.nullcontext() as excinfo:
5254
pass
5355
assert_type(excinfo, Optional[pytest.ExceptionInfo[RuntimeError]])
56+
57+
58+
# Issue #12941.
59+
def check_testreport_attributes(report: TestReport) -> None:
60+
assert_type(report.when, Literal["setup", "call", "teardown"])
61+
assert_type(report.location, tuple[str, Optional[int], str])

0 commit comments

Comments
 (0)