Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/pytest_tap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
from tap.formatter import format_as_diagnostics
from tap.tracker import Tracker
from tap.tracker import ENABLE_VERSION_13, Tracker

SHOW_CAPTURE_LOG = ("log", "all")
SHOW_CAPTURE_OUT = ("stdout", "all")
Expand Down Expand Up @@ -83,6 +83,9 @@ def pytest_runtest_logreport(self, report: pytest.TestReport):
self._tracker.add_ok(testcase, description, diagnostics=diagnostics)
elif report.failed:
diagnostics = _make_as_diagnostics(report, self.show_capture)
raw_yaml_block = (
_make_as_raw_yaml_block(report) if ENABLE_VERSION_13 else None
)

# pytest treats an unexpected success from unitest.expectedFailure
# as a failure.
Expand All @@ -108,7 +111,12 @@ def pytest_runtest_logreport(self, report: pytest.TestReport):
)
return

self._tracker.add_not_ok(testcase, description, diagnostics=diagnostics)
self._tracker.add_not_ok(
testcase,
description,
diagnostics=diagnostics,
raw_yaml_block=raw_yaml_block,
)
elif report.skipped:
reason = report.longrepr[2].split(":", 1)[1].strip() # type: ignore
self._tracker.add_skip(testcase, description, reason)
Expand Down Expand Up @@ -201,3 +209,18 @@ def _make_as_diagnostics(report, show_capture):
)

return format_as_diagnostics(lines)


def _make_as_raw_yaml_block(report):
try:
lines = report.longrepr.reprcrash.message.splitlines(keepends=True)
except AttributeError:
lines = report.longreprtext.splitlines(keepends=True)
res = f"""\
message: |
{"".join(f" {line}" for line in lines)}
severity: {report.outcome}
duration_ms: {report.duration * 1000}"""
if hasattr(report, "user_properties"):
res += "\n" + "\n".join(f"{k}: {v}" for k, v in report.user_properties)
return res
Loading