|
17 | 17 |
|
18 | 18 | import _pytest._code |
19 | 19 | from _pytest._code import getfslineno |
20 | | -from _pytest._code.code import ExceptionChainRepr |
21 | 20 | from _pytest._code.code import ExceptionInfo |
22 | | -from _pytest._code.code import ReprExceptionInfo |
| 21 | +from _pytest._code.code import TerminalRepr |
23 | 22 | from _pytest.compat import cached_property |
24 | 23 | from _pytest.compat import overload |
25 | 24 | from _pytest.compat import TYPE_CHECKING |
|
28 | 27 | from _pytest.deprecated import NODE_USE_FROM_PARENT |
29 | 28 | from _pytest.fixtures import FixtureDef |
30 | 29 | from _pytest.fixtures import FixtureLookupError |
31 | | -from _pytest.fixtures import FixtureLookupErrorRepr |
32 | 30 | from _pytest.mark.structures import Mark |
33 | 31 | from _pytest.mark.structures import MarkDecorator |
34 | 32 | from _pytest.mark.structures import NodeKeywords |
35 | 33 | from _pytest.outcomes import fail |
36 | | -from _pytest.outcomes import Failed |
37 | 34 | from _pytest.store import Store |
38 | 35 |
|
39 | 36 | if TYPE_CHECKING: |
|
42 | 39 | # Imported here due to circular import. |
43 | 40 | from _pytest.main import Session |
44 | 41 | from _pytest.warning_types import PytestWarning |
| 42 | + from _pytest._code.code import _TracebackStyle |
45 | 43 |
|
46 | 44 |
|
47 | 45 | SEP = "/" |
@@ -354,8 +352,10 @@ def _prunetraceback(self, excinfo): |
354 | 352 | pass |
355 | 353 |
|
356 | 354 | def _repr_failure_py( |
357 | | - self, excinfo: ExceptionInfo[Union[Failed, FixtureLookupError]], style=None |
358 | | - ) -> Union[str, ReprExceptionInfo, ExceptionChainRepr, FixtureLookupErrorRepr]: |
| 355 | + self, |
| 356 | + excinfo: ExceptionInfo[BaseException], |
| 357 | + style: "Optional[_TracebackStyle]" = None, |
| 358 | + ) -> Union[str, TerminalRepr]: |
359 | 359 | if isinstance(excinfo.value, fail.Exception): |
360 | 360 | if not excinfo.value.pytrace: |
361 | 361 | return str(excinfo.value) |
@@ -398,8 +398,10 @@ def _repr_failure_py( |
398 | 398 | ) |
399 | 399 |
|
400 | 400 | def repr_failure( |
401 | | - self, excinfo, style=None |
402 | | - ) -> Union[str, ReprExceptionInfo, ExceptionChainRepr, FixtureLookupErrorRepr]: |
| 401 | + self, |
| 402 | + excinfo: ExceptionInfo[BaseException], |
| 403 | + style: "Optional[_TracebackStyle]" = None, |
| 404 | + ) -> Union[str, TerminalRepr]: |
403 | 405 | """ |
404 | 406 | Return a representation of a collection or test failure. |
405 | 407 |
|
@@ -445,13 +447,16 @@ def collect(self) -> Iterable[Union["Item", "Collector"]]: |
445 | 447 | """ |
446 | 448 | raise NotImplementedError("abstract") |
447 | 449 |
|
448 | | - def repr_failure(self, excinfo): |
| 450 | + # TODO: This omits the style= parameter which breaks Liskov Substitution. |
| 451 | + def repr_failure( # type: ignore[override] |
| 452 | + self, excinfo: ExceptionInfo[BaseException] |
| 453 | + ) -> Union[str, TerminalRepr]: |
449 | 454 | """ |
450 | 455 | Return a representation of a collection failure. |
451 | 456 |
|
452 | 457 | :param excinfo: Exception information for the failure. |
453 | 458 | """ |
454 | | - if excinfo.errisinstance(self.CollectError) and not self.config.getoption( |
| 459 | + if isinstance(excinfo.value, self.CollectError) and not self.config.getoption( |
455 | 460 | "fulltrace", False |
456 | 461 | ): |
457 | 462 | exc = excinfo.value |
|
0 commit comments