import os
import platform
import sys
from py.xml import html
import pytest
import time
def pytest_html_report_title(report):
report.title = "OpenHarmony Build Test Report"
@pytest.mark.optionalhook
def pytest_metadata(metadata):
metadata.clear()
metadata['Python Version'] = sys.version
metadata['Cpu Count'] = os.cpu_count()
metadata["System Info"] = platform.platform()
try:
disk_info = os.statvfs('/')
total_disk = round(float(disk_info.f_frsize * disk_info.f_blocks) / (1024 ** 3), 4)
metadata["Disk Size"] = "{} GB".format(total_disk)
with open('/proc/meminfo', 'r') as f:
lines = f.readlines()
total_memory_line = [line for line in lines if line.startswith('MemTotal')]
total_memory = round(float(total_memory_line[0].split()[1]) / (1024 ** 2), 4) if total_memory_line else " "
metadata["Totla Memory"] = "{} GB".format(total_memory)
except Exception as e:
print(e)
def pytest_html_results_table_header(cells):
cells.insert(2, html.th("Description", class_="sortable desc", col="desc"))
cells.insert(1, html.th("Time", class_="sortable time", col="time"))
cells.pop()
def pytest_html_results_table_row(report, cells):
cells.insert(2, html.th(report.description))
cells.insert(1, html.th(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), class_="col-time"))
cells.pop()
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
if str(item.function.__doc__) != "None":
report.description = str(item.function.__doc__)
else:
report.description = "this is description info"