From a02f8c39d99fcabb8138597d99901f414c28330d Mon Sep 17 00:00:00 2001 From: Brian Okken <1568356+okken@users.noreply.github.com> Date: Sat, 27 Apr 2024 18:53:50 -0700 Subject: [PATCH] add --xfail-tb to be able to turn off or separately control xfail tb style --- src/_pytest/terminal.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 724d5c54d..9e4d51bd2 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -216,6 +216,15 @@ def pytest_addoption(parser: Parser) -> None: choices=["auto", "long", "short", "no", "line", "native"], help="Traceback print mode (auto/long/short/line/native/no)", ) + group._addoption( + "--xfail-tb", + metavar="style", + action="store", + dest="xfail_tbstyle", + default="auto", + choices=["auto", "long", "short", "no", "line", "native"], + help="Traceback print mode for xfail(auto/long/short/line/native/no)", + ) group._addoption( "--show-capture", action="store", @@ -1074,18 +1083,22 @@ class TerminalReporter: self.summary_failures_combined("failed", "FAILURES") def summary_xfailures(self) -> None: - self.summary_failures_combined("xfailed", "XFAILURES", "x") + style = self.config.option.xfail_tbstyle + self.summary_failures_combined("xfailed", "XFAILURES", "x", style=style) def summary_failures_combined( - self, which_reports: str, sep_title: str, needed_opt: Optional[str] = None + self, which_reports: str, sep_title: str, needed_opt: Optional[str] = None, style = None ) -> None: - if self.config.option.tbstyle != "no": + if style is None: + style == self.config.option.tbstyle + + if style != "no": if not needed_opt or self.hasopt(needed_opt): reports: List[BaseReport] = self.getreports(which_reports) if not reports: return self.write_sep("=", sep_title) - if self.config.option.tbstyle == "line": + if style == "line": for rep in reports: line = self._getcrashline(rep) self.write_line(line)