import pytest
from py.xml import html
# #删除所有成功用例的钩子函数#?
# @pytest.mark.optionalhook
# def pytest_html_results_table_row(report, cells):
# if report.passed:
# del cells[:]
#清除所有成功用例的日志
# @pytest.mark.optionalhook
# def pytest_html_results_table_html(report, data):
# if report.passed:
# del data[:]
# data.append(html.div('No log output captured.', class_='empty log'))
#添加标题
@pytest.mark.optionalhook
def pytest_html_results_table_header(cells):
cells.insert(2, html.th('compile_time'))
cells.insert(1, html.th('execute_time', class_='sortable time', col='time'))
# cells.pop()
#添加内容
@pytest.mark.optionalhook
def pytest_html_results_table_row(report, cells):
cells.insert(2, html.td(report.compile_time))
cells.insert(1, html.td(report.execute_time))
# cells.pop()
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
report.compile_time = f"N/A"
report.execute_time = f"N/A"
if item.user_properties:
test_properties = { prop[0]: prop[1] for prop in item.user_properties }
# These are added via `record_property` fixture and I am able to access them with no issue.
report.compile_time = test_properties["compile_time"]
report.execute_time = test_properties["execute_time"]
import pytest
from py.xml import html
@pytest.mark.parametrize('foo, bar, baz', [(1, 2, 3),(4, 5, 9),(4, 6, 10),(2,5,8)])
def test_example(record_property, foo, bar, baz):
compile_time = 32
execute_time = 54
assert foo + bar == baz
record_property("compile_time", compile_time)
record_property("execute_time", execute_time)