Skip to content

Commit 274da9c

Browse files
committed
CI debug: add GitHub annotation output for test failures
1 parent 7b742e0 commit 274da9c

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@
1010
import wrapt
1111
from webtest import TestApp
1212

13+
14+
# Temporary: output GitHub annotations for test failures so we can debug CI
15+
def pytest_runtest_makereport(item, call):
16+
"""Output GitHub Actions annotations for failed tests."""
17+
if call.when == "call" and call.excinfo is not None:
18+
import traceback
19+
20+
tb = "".join(traceback.format_exception(call.excinfo.type, call.excinfo.value, call.excinfo.tb))
21+
# GitHub annotations can't have newlines, encode them
22+
msg = tb.replace("\n", "%0A").replace("\r", "%0D")
23+
fspath = str(item.fspath) if hasattr(item, "fspath") else ""
24+
line = item.reportinfo()[1] if item.reportinfo()[1] else 0
25+
print(f"\n::error file={fspath},line={line},title=Test Failure: {item.nodeid}::{msg}")
26+
elif call.when == "setup" and call.excinfo is not None:
27+
import traceback
28+
29+
tb = "".join(traceback.format_exception(call.excinfo.type, call.excinfo.value, call.excinfo.tb))
30+
msg = tb.replace("\n", "%0A").replace("\r", "%0D")
31+
print(f"\n::error title=Setup Failure: {item.nodeid}::{msg}")
32+
1333
from scout_apm.core import error_service as scout_apm_core_error_service
1434
from scout_apm.core.agent import socket as scout_apm_core_socket
1535
from scout_apm.core.agent.manager import CoreAgentManager

0 commit comments

Comments
 (0)