我正在尝试阅读pytest-html的源代码,不知道它如何获得结果。 如果我添加了@ pytest.mark.p0之类的标记,我想在pytest-html报告中显示该标记,例如使用官方演示添加说明,如何添加它。
答案 0 :(得分:0)
我自己解决。像描述
@pytest.mark.optionalhook
def pytest_html_results_table_header(cells):
#<th class="sortable result initial-sort asc inactive" col="result"><div class="sort-icon">vvv</div>Result</th>
cells.insert(1, html.th('Description'))
cells.insert(2, html.th('Priority', class_="sortable", col="priority"))
cells.insert(3, html.th('Owner', class_="sortable", col="owner"))
cells.pop()
@pytest.mark.optionalhook
def pytest_html_results_table_row(report, cells):
cells.insert(1, html.td(report.description))
cells.insert(2, html.td(report.priority))
cells.insert(3, html.td(report.owner))
cells.pop()
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
report.description = str(item.function.__doc__)
marker_priority = item.get_closest_marker("priority")
if marker_priority:
report.priority = marker_priority.kwargs['value']
#print(marker_priority)
marker_owner = item.get_closest_marker("owner")
if marker_owner:
report.owner = marker_owner.kwargs['name']