Skip to content

Commit 50e16db

Browse files
author
Cody D'Ambrosio
committed
Support TAP13 YAML
1 parent aba9dfa commit 50e16db

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/pytest_tap/plugin.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import pytest
55
from tap.formatter import format_as_diagnostics
6-
from tap.tracker import Tracker
6+
from tap.tracker import Tracker, ENABLE_VERSION_13
7+
78

89
SHOW_CAPTURE_LOG = ("log", "all")
910
SHOW_CAPTURE_OUT = ("stdout", "all")
@@ -83,6 +84,7 @@ def pytest_runtest_logreport(self, report: pytest.TestReport):
8384
self._tracker.add_ok(testcase, description, diagnostics=diagnostics)
8485
elif report.failed:
8586
diagnostics = _make_as_diagnostics(report, self.show_capture)
87+
raw_yaml_block = _make_as_raw_yaml_block(report) if ENABLE_VERSION_13 else None
8688

8789
# pytest treats an unexpected success from unitest.expectedFailure
8890
# as a failure.
@@ -108,7 +110,7 @@ def pytest_runtest_logreport(self, report: pytest.TestReport):
108110
)
109111
return
110112

111-
self._tracker.add_not_ok(testcase, description, diagnostics=diagnostics)
113+
self._tracker.add_not_ok(testcase, description, diagnostics=diagnostics, raw_yaml_block=raw_yaml_block)
112114
elif report.skipped:
113115
reason = report.longrepr[2].split(":", 1)[1].strip() # type: ignore
114116
self._tracker.add_skip(testcase, description, reason)
@@ -201,3 +203,16 @@ def _make_as_diagnostics(report, show_capture):
201203
)
202204

203205
return format_as_diagnostics(lines)
206+
207+
208+
def _make_as_raw_yaml_block(report):
209+
try:
210+
lines = report.longrepr.reprcrash.message.splitlines(keepends=True)
211+
except AttributeError:
212+
lines = report.longreprtext.splitlines(keepends=True)
213+
return f"""\
214+
message: |
215+
{''.join(f' {line}' for line in lines)}
216+
severity: {report.outcome}
217+
duration_ms: {report.duration * 1000}
218+
"""

0 commit comments

Comments
 (0)