我正在尝试阅读 pytest-html 的源代码,不知道如何获得结果.. 如果我添加像 @pytest.mark.p0 这样的标记,我想在 pytest-html 报告中显示这个标记,喜欢用官方演示添加描述,如何添加它。
问问题
227 次
1 回答
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']
于 2019-11-02T05:33:26.763 回答