Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Enhanced py-utils test_framework to generate test_report after tests …
Browse files Browse the repository at this point in the history
…execution. (#713)

* Enhanced py-utils test_framework to generate test_report after tests execution.

Signed-off-by: Veerendra Garikipati <[email protected]>

* Update main.py

Co-authored-by: Sachin Punadikar <[email protected]>
  • Loading branch information
veerendra-simha-garikipati and Sachin Punadikar authored Jan 21, 2022
1 parent 975daf8 commit 28966f1
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
93 changes: 93 additions & 0 deletions py-utils/src/test_framework/generate_test_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env python3

# CORTX-Py-Utils: CORTX Python common library.
# Copyright (c) 2022 Seagate Technology LLC and/or its Affiliates
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# For any questions about this software or licensing,
# please email [email protected] or [email protected].

header_template = """
<!DOCTYPE html>
<html>
<head>
<style>
#result {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 80%;
}
#result td, #result th {
border: 1px solid #ddd;
padding: 8px;
}
#result tr:nth-child(even){background-color: #f2f2f2;}
#result tr:hover {background-color: #ddd;}
#result th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<table id="result">
<tr>
<th>Test Suite</th>
<th>Status</th>
<th>Duration</th>
</tr>"""

result_template = """
<tr>
<td>{testsuite}</td>
<td>{status}</td>
<td>{duration}s</td>
</tr>"""

footer_template = """
</table><br>
Overall Status: {}<br>
Total Test Suites: {}<br>
Passed: {}<br>
Failed: {}<br>
Time Taken: {}s<br>
</body></html>"""

def generate_html_report(test_result):
"""
Generates HTML test_report under /tmp.
"""
result_table = ''
overall_status = 'Passed'
total_ts = 0
total_failed = 0
time_taken=0
for ts, value in test_result.items():
status = list(value.keys())[0]
duration = int(list(value.values())[0])
if status.lower() == 'fail':
overall_status = 'Failed'
total_failed += 1
st_style = "<p style='color:red'>"
st_end = "</p>"
status = st_style + status + st_end
result_table += result_template.format(testsuite=ts, status=status, \
duration=duration)
total_ts += 1
time_taken += duration
footer = footer_template.format(overall_status, total_ts, \
total_ts-total_failed, total_failed, time_taken)
test_data = header_template + result_table + footer
with open('/tmp/py_utils_test_report.html', 'w') as test_report:
test_report.write(test_data)
5 changes: 5 additions & 0 deletions py-utils/src/test_framework/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from cortx.test_framework import const
from cortx.utils.errors import TestFailed
from cortx.test_framework.generate_test_report import generate_html_report


class TestRunner:
Expand Down Expand Up @@ -239,3 +240,7 @@ def execute_tests(args):
print("\n********* Test Execution Completed *********")
TestRunner._test_report(ts_count, test_count, pass_count, fail_count, \
total_start_time, result)

generate_html_report(result)
print("\n##### Test report 'py_utils_test_report.html' is "\
"generated at /tmp #####\n")

0 comments on commit 28966f1

Please sign in to comment.