有没有办法在每个测试的 pytest-html 报告中显示测试作者姓名?
问问题
34 次
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 回答