|
16 | 16 | import py |
17 | 17 |
|
18 | 18 | import _pytest._code |
19 | | -from _pytest._code.code import ExceptionChainRepr |
20 | 19 | from _pytest._code.code import ExceptionInfo |
21 | | -from _pytest._code.code import ReprExceptionInfo |
| 20 | +from _pytest._code.code import TerminalRepr |
22 | 21 | from _pytest._code.source import getfslineno |
23 | 22 | from _pytest.compat import cached_property |
24 | 23 | from _pytest.compat import overload |
|
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: |
40 | 37 | from typing import Type |
41 | 38 |
|
42 | 39 | from _pytest.main import Session |
43 | 40 | from _pytest.warning_types import PytestWarning |
| 41 | + from _pytest._code.code import _TracebackStyle |
44 | 42 |
|
45 | 43 | SEP = "/" |
46 | 44 |
|
@@ -339,8 +337,10 @@ def _prunetraceback(self, excinfo): |
339 | 337 | pass |
340 | 338 |
|
341 | 339 | def _repr_failure_py( |
342 | | - self, excinfo: ExceptionInfo[Union[Failed, FixtureLookupError]], style=None |
343 | | - ) -> Union[str, ReprExceptionInfo, ExceptionChainRepr, FixtureLookupErrorRepr]: |
| 340 | + self, |
| 341 | + excinfo: ExceptionInfo[BaseException], |
| 342 | + style: "Optional[_TracebackStyle]" = None, |
| 343 | + ) -> Union[str, TerminalRepr]: |
344 | 344 | if isinstance(excinfo.value, fail.Exception): |
345 | 345 | if not excinfo.value.pytrace: |
346 | 346 | return str(excinfo.value) |
@@ -383,8 +383,10 @@ def _repr_failure_py( |
383 | 383 | ) |
384 | 384 |
|
385 | 385 | def repr_failure( |
386 | | - self, excinfo, style=None |
387 | | - ) -> Union[str, ReprExceptionInfo, ExceptionChainRepr, FixtureLookupErrorRepr]: |
| 386 | + self, |
| 387 | + excinfo: ExceptionInfo[BaseException], |
| 388 | + style: "Optional[_TracebackStyle]" = None, |
| 389 | + ) -> Union[str, TerminalRepr]: |
388 | 390 | """ |
389 | 391 | Return a representation of a collection or test failure. |
390 | 392 |
|
@@ -430,13 +432,16 @@ def collect(self) -> Iterable[Union["Item", "Collector"]]: |
430 | 432 | """ |
431 | 433 | raise NotImplementedError("abstract") |
432 | 434 |
|
433 | | - def repr_failure(self, excinfo): |
| 435 | + # TODO: This omits the style= parameter which breaks Liskov Substitution. |
| 436 | + def repr_failure( # type: ignore[override] # noqa: F821 |
| 437 | + self, excinfo: ExceptionInfo[BaseException] |
| 438 | + ) -> Union[str, TerminalRepr]: |
434 | 439 | """ |
435 | 440 | Return a representation of a collection failure. |
436 | 441 |
|
437 | 442 | :param excinfo: Exception information for the failure. |
438 | 443 | """ |
439 | | - if excinfo.errisinstance(self.CollectError) and not self.config.getoption( |
| 444 | + if isinstance(excinfo.value, self.CollectError) and not self.config.getoption( |
440 | 445 | "fulltrace", False |
441 | 446 | ): |
442 | 447 | exc = excinfo.value |
|
0 commit comments