nodes: change _prunetraceback to return the new traceback instead of modifying excinfo

This makes it usable as a general function, and just more understandable
in general.
This commit is contained in:
Ran Benita
2023-04-13 13:48:44 +03:00
parent 6f7f89f3c4
commit fcada1ea47
3 changed files with 23 additions and 17 deletions

View File

@@ -1802,7 +1802,7 @@ class Function(PyobjMixin, nodes.Item):
def setup(self) -> None:
self._request._fillfixtures()
def _prunetraceback(self, excinfo: ExceptionInfo[BaseException]) -> None:
def _traceback_filter(self, excinfo: ExceptionInfo[BaseException]) -> Traceback:
if hasattr(self, "_obj") and not self.config.getoption("fulltrace", False):
code = _pytest._code.Code.from_function(get_real_func(self.obj))
path, firstlineno = code.path, code.firstlineno
@@ -1814,19 +1814,22 @@ class Function(PyobjMixin, nodes.Item):
ntraceback = ntraceback.filter(filter_traceback)
if not ntraceback:
ntraceback = traceback
ntraceback = ntraceback.filter(excinfo)
excinfo.traceback = ntraceback.filter(excinfo)
# issue364: mark all but first and last frames to
# only show a single-line message for each frame.
if self.config.getoption("tbstyle", "auto") == "auto":
if len(excinfo.traceback) > 2:
excinfo.traceback = Traceback(
if len(ntraceback) > 2:
ntraceback = Traceback(
entry
if i == 0 or i == len(excinfo.traceback) - 1
if i == 0 or i == len(ntraceback) - 1
else entry.with_repr_style("short")
for i, entry in enumerate(excinfo.traceback)
for i, entry in enumerate(ntraceback)
)
return ntraceback
return excinfo.traceback
# TODO: Type ignored -- breaks Liskov Substitution.
def repr_failure( # type: ignore[override]
self,