Skip to content

Commit

Permalink
Fix xfail/xpass handling (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Bong authored Jan 25, 2022
1 parent 89c5274 commit 320be5e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.2] - 2022/01/25

### Fixed

Fix XFAIL/XPASS handling

## [1.0.1] - 2021/11/24

### Fixed
Expand Down
40 changes: 27 additions & 13 deletions pytest_pretty_terminal/_pretty_terminal_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"passed": {"green": True, "bold": True},
"failed": {"red": True, "bold": True},
"blocked": {"blue": True, "bold": True},
"skipped": {"yellow": True, "bold": True}
"skipped": {"yellow": True, "bold": True},
"xfailed": {"yellow": True, "bold": True},
"xpassed": {"yellow": True, "bold": True}
}


Expand Down Expand Up @@ -57,7 +59,14 @@ def pytest_runtest_logreport(self, report: TestReport):

terminal_writer: TerminalWriter = self.config.get_terminal_writer()
fill = terminal_writer.fullwidth - terminal_writer.width_of_current_line - 1
outcome = "blocked" if getattr(report, "blocked", False) else report.outcome # Establish compatibility to pytest-adaptavist
if getattr(report, "blocked", False):
outcome = "blocked"
elif hasattr(report, "wasxfail") and report.outcome == "skipped":
outcome = "xfailed"
elif hasattr(report, "wasxfail") and report.outcome == "passed":
outcome = "xpassed"
else:
outcome = report.outcome

self.terminal_reporter.write_sep("-", bold=True)
self.terminal_reporter.write_line(outcome.upper().rjust(fill), **COLORMAP.get(outcome, {}))
Expand All @@ -70,17 +79,22 @@ def pytest_report_teststatus(self, report: TestReport) -> Optional[Tuple[str, st
:param report: The report object whose status is to be returned
"""
if getattr(self.config.option, "pretty", False):
outcome: str = report.outcome
if report.when in ("collect", "setup", "teardown"):
if outcome == "failed":
outcome = "error"
elif getattr(report, "blocked", False): # Establish compatibility to pytest-adaptavist
outcome = "blocked"
elif not report.skipped:
outcome = ""
return outcome, "", ""
return None
if not getattr(self.config.option, "pretty", False):
return None

outcome: str = report.outcome
if report.when in ("collect", "setup", "teardown"):
if hasattr(report, "wasxfail") and report.skipped:
outcome = "xfailed"
elif hasattr(report, "wasxfail") and report.passed:
outcome = "xpassed"
elif outcome == "failed":
outcome = "error"
elif getattr(report, "blocked", False): # Establish compatibility to pytest-adaptavist
outcome = "blocked"
elif not report.skipped:
outcome = ""
return outcome, "", ""

def _print_docstring_and_params(self, title: str, user_properties: Dict[str, Any]):
"""Print docstring and parameters of a test case."""
Expand Down

0 comments on commit 320be5e

Please sign in to comment.