Pytest—HTML报告修改

conftest.py 内做修改

import pytest
from py._xmlgen import html
'''
pytest里面默认读取conftest.py里面的配置


conftest.py配置需要注意以下点:
    conftest.py配置脚本名称是固定的,不能改名称
    conftest.py与运行的用例要在同一个pakage下,并且有__init__.py文件
    不需要import导入 conftest.py,pytest用例会自动查找
'''
# def pytest_html_report_title(report):
#     report.title = "My very own title!"




'''Environment 修改
    pytest-metadata提供Environment section,
    通过pytest_configure访问 '''
def pytest_configure(config):
    # 添加接口地址与项目名称
    config._metadata["项目名称"] = "SuperTest v1.0"
    config._metadata['接口地址'] = 'https://www.baidu.com/'
    # 删除Java_Home
    config._metadata.pop("JAVA_HOME")


'''Additional summary information  
    附加摘要信息'''
def pytest_html_results_summary(prefix, summary, postfix):
    prefix.extend([html.p("所属部门: 帝国测试中心")])
    prefix.extend([html.p("负责人: 蒙奇·D·路飞")])




'''在报表对象上创建'额外'列表,从而向HTML报告添加详细信息'''
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    pytest_html = item.config.pluginmanager.getplugin('html')
    outcome = yield
    report = outcome.get_result()
    extra = getattr(report, 'extra', [])
    if report.when == 'call':
        # always add url to report
        extra.append(pytest_html.extras.url('http://www.baidu.com/'))
        xfail = hasattr(report, 'wasxfail')
        if (report.skipped and xfail) or (report.failed and not xfail):
            # only add additional html on failure
            extra.append(pytest_html.extras.html('
Additional HTML
')) report.extra = extra

 

你可能感兴趣的:(Pytest—HTML报告修改)