Как добавить отметку в отчете pytest-html - PullRequest
0 голосов
/ 02 ноября 2019

Я пытаюсь прочитать исходный код pytest-html, не знаю, как получить результаты ... если я добавлю метку, например @ pytest.mark.p0, я хочу показать эту метку в pytest-HTML-отчет, как добавить описание с официальной демонстрацией, как его добавить.

1 Ответ

0 голосов
/ 02 ноября 2019

Я разрешаю это сам. как описание

@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']
...