Skip to content

Commit 7af7a03

Browse files
committed
[Backend Tester] Add error message field to CSV report
ghstack-source-id: ddcbb38 ghstack-comment-id: 3257219383 Pull-Request: #13991
1 parent 205e70a commit 7af7a03

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

backends/test/suite/generate_markdown_summary.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@
1212
#
1313

1414

15+
def escape_for_markdown(text: str) -> str:
16+
"""
17+
Modify a string to properly display in a markdown table cell.
18+
"""
19+
if not text:
20+
return text
21+
22+
# Replace newlines with <br /> tags
23+
escaped = text.replace('\n', '<br />')
24+
25+
# Escape backslashes.
26+
escaped = escaped.replace('\\', '\\\\')
27+
28+
# Escape pipe characters that would break table structure
29+
escaped = escaped.replace('|', '\\|')
30+
31+
return escaped
32+
33+
1534
def generate_markdown(csv_path: str, exit_code: int = 0): # noqa (C901)
1635
# Print warning if exit code is non-zero
1736
if exit_code != 0:
@@ -46,7 +65,7 @@ def generate_markdown(csv_path: str, exit_code: int = 0): # noqa (C901)
4665

4766
for row in data_rows:
4867
# Make a copy of the row to avoid modifying the original
49-
processed_row = row.copy()
68+
processed_row = [escape_for_markdown(cell) for cell in row]
5069

5170
# Count results and collect failed tests
5271
if result_column_index is not None and result_column_index < len(row):
@@ -96,7 +115,8 @@ def generate_markdown(csv_path: str, exit_code: int = 0): # noqa (C901)
96115
# Generate Failed Tests section
97116
print("# Failed Tests\n")
98117
if failed_tests:
99-
print("| " + " | ".join(header) + " |")
118+
escaped_header = [escape_for_markdown(col) for col in header]
119+
print("| " + " | ".join(escaped_header) + " |")
100120
print("|" + "|".join(["---"] * len(header)) + "|")
101121
for row in failed_tests:
102122
print("| " + " | ".join(row) + " |")

backends/test/suite/reporting.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
]
4646
)
4747

48+
CSV_FIELD_NAMES.append("Error")
49+
4850

4951
# Operators that are excluded from the counts returned by count_ops. These are used to
5052
# exclude operatations that are not logically relevant or delegatable to backends.
@@ -365,6 +367,15 @@ def write_csv_header(output: TextIO):
365367
def write_csv_row(record: TestCaseSummary, output: TextIO):
366368
writer = csv.DictWriter(output, CSV_FIELD_NAMES)
367369

370+
# Truncate error message if it's too long, keeping first and last 200 characters
371+
error_message = ""
372+
if record.error is not None:
373+
error_str = str(record.error)
374+
if len(error_str) > 400:
375+
error_message = error_str[:200] + "..." + error_str[-200:]
376+
else:
377+
error_message = error_str
378+
368379
row = {
369380
"Test ID": record.name,
370381
"Test Case": record.base_name,
@@ -373,6 +384,7 @@ def write_csv_row(record: TestCaseSummary, output: TextIO):
373384
"Params": _serialize_params(record.params),
374385
"Result": record.result.to_short_str(),
375386
"Result Detail": record.result.to_detail_str(),
387+
"Error": error_message,
376388
"Delegated": "True" if record.is_delegated() else "False",
377389
"Quantize Time (s)": (
378390
f"{record.quantize_time.total_seconds():.3f}"

0 commit comments

Comments
 (0)