-1

有没有办法在每个测试的 pytest-html 报告中显示测试作者姓名?

4

1 回答 1

0

是的。你可以这样做。将__author__属性放在每个测试模块中。

# test_add.py

__author__ = 'Vivek R'


def add(x, y):
    return x + y


def test_add():
    assert add(5, 4) == 9

conftest.py并在文件中调用一些固定装置。

# conftest.py

from py.xml import html
import pytest


def pytest_html_results_table_header(cells):
    cells.append(html.th("Author"))


def pytest_html_results_table_row(report, cells):
    cells.append(html.td(report.author))


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    report.author = item.module.__author__

在此处输入图像描述

于 2022-01-11T09:49:58.257 回答