由原生的報(bào)告思考問(wèn)題:
? ? 根據(jù)默認(rèn)的命令,生成的報(bào)告均為英文保礼,不適合廣泛閱讀沛励?
? ? 報(bào)告中三個(gè)模塊:Environment、Summary氓英、Results侯勉?
從官方文檔中,可以找到修改的方法:
官方文檔鏈接:https://pypi.org/project/pytest-html/
前提:
當(dāng)前使用版本:python3.7.5? 铝阐,pytest 5.3.5? ?pytest-html2.0.1
配置conftest.py文件(該文件為pytest項(xiàng)目下的fixture集中配置地方)址貌,有興趣的同學(xué),可以深入pytest.fixture(https://docs.pytest.org/en/latest/contents.html)
操作conftest.py:
from datetimeimport datetime
import pytest
from py.xmlimport html
# 修改ENviroment的內(nèi)容
def pytest_configure(config):
????# 添加接口地址與項(xiàng)目名稱
? ? config._metadata["項(xiàng)目名稱"] ="測(cè)試pytest項(xiàng)目"
? ? config._metadata["測(cè)試case地址"] ="D:\python\Apitest\test_Case"
? ? # 刪除java_Home
? ? config._metadata.pop("JAVA_HOME")
????config._metadata.pop("Python")
????config._metadata.pop("Packages")\
# 修改summary內(nèi)容
@pytest.mark.optionalhook
def pytest_html_results_summary(prefix, summary, postfix):
????prefix.extend([html.p("所屬部門:xx測(cè)試組")])
????prefix.extend(([html.p("測(cè)試人員:歐陽(yáng)二蛋")]))
# 修改result_table中內(nèi)容
def pytest_html_results_table_header(cells):
????cells.insert(2, html.th('Description'))
????cells.insert(3, html.th('Time', class_='sortable time', col='time'))
????cells.pop()
def pytest_html_results_table_row(report, cells):
????cells.insert(2, html.td(report.description))
????cells.insert(3, html.td(datetime.utcnow(), class_='col-time'))
????cells.pop()
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
????outcome =yield
? ? report = outcome.get_result()
????report.description =str(item.function.__doc__)
????report.nodeid = report.nodeid.encode("utf-8").decode("unicode_escape")#設(shè)置編碼顯示中文
最終結(jié)果展示:
Tips:
? ? 文檔中還有圖片徘键、文件等操作的相關(guān)操作练对,有興趣的可以深入了解下。