Skip to content

Commit 94d01bc

Browse files
committed
[run-qemu][print_test_summary] build_summaries_for_test to generate
individual test summaries The logic between handling summaries for test and subtest was very similar. This function receive a (sub)test dict and generate its textual summaries for both GH job summary and GH test console. When asubtest is used, the parent test name and number must be passed as arguments to the function. Signed-off-by: Manu Bretelle <[email protected]>
1 parent 5f882a3 commit 94d01bc

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

run-qemu/print_test_summary.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import argparse
1111
import json
1212

13-
from typing import Tuple
13+
from typing import Tuple, Dict, Optional
1414

1515

1616
def parse_args():
@@ -45,7 +45,7 @@ def error(text: str) -> str:
4545

4646
def markdown_summary(json_summary: json):
4747
return f"""- :heavy_check_mark: Success: {json_summary['success']}/{json_summary['success_subtest']}
48-
- :next_track_button: Skipped: ${json_summary['skipped']}
48+
- :next_track_button: Skipped: {json_summary['skipped']}
4949
- :x: Failed: {json_summary['failed']}"""
5050

5151

@@ -70,29 +70,41 @@ def test_error_console_log(test_error: str, test_message: str) -> str:
7070
return error_msg
7171

7272

73+
def build_summaries_for_test(
74+
test: Dict, parent_name: Optional[str] = None, parent_number: Optional[int] = None
75+
) -> Optional[Tuple[str, str]]:
76+
if not test["failed"]:
77+
return None
78+
test_log = f"#{test['number']} {test['name']}"
79+
if parent_number and parent_name:
80+
test_log = f"#{parent_number}/{test['number']} {parent_name}/{test['name']}"
81+
gh_summary = test_log
82+
console_summary = test_error_console_log(test_log, test["message"])
83+
return (gh_summary, console_summary)
84+
85+
7386
def build_summaries(json_summary) -> Tuple[str, str]:
87+
"""
88+
Given a json summary, return strings formatted for the GH summary and GH test step console respectively.
89+
"""
7490
gh_summary = ["# Tests summary"]
7591
gh_summary.append(markdown_summary(json_summary))
7692

7793
console_summary = [notice(log_summary(json_summary))]
7894

7995
for test in json_summary["results"]:
80-
test_name = test["name"]
81-
test_number = test["number"]
82-
if test["failed"]:
83-
test_log = f"#{test_number} {test_name}"
84-
gh_summary.append(test_log)
85-
console_summary.append(test_error_console_log(test_log, test["message"]))
96+
test_summaries = build_summaries_for_test(test, None, None)
97+
if test_summaries:
98+
gh_summary.append(test_summaries[0])
99+
console_summary.append(test_summaries[1])
86100

87101
for subtest in test["subtests"]:
88-
if subtest["failed"]:
89-
subtest_log = (
90-
f"#{test_number}/{subtest['number']} {test_name}/{subtest['name']}"
91-
)
92-
gh_summary.append(subtest_log)
93-
console_summary.append(
94-
test_error_console_log(subtest_log, subtest["message"])
95-
)
102+
subtest_summaries = build_summaries_for_test(
103+
subtest, parent_name=test["name"], parent_number=test["number"]
104+
)
105+
if subtest_summaries:
106+
gh_summary.append(subtest_summaries[0])
107+
console_summary.append(subtest_summaries[1])
96108

97109
return "\n".join(gh_summary), "\n".join(console_summary)
98110

0 commit comments

Comments
 (0)