• pytest-html报告自定义字段


    from datetime import datetime
    from py.xml import html
    import pytest
    import time
    import pytest
    from py.xml import html
    
    def pytest_html_report_title(report):
       report.title = "接口自动化测试报告" #修改报告名称
    
    # def pytest_html_results_summary(prefix, summary, postfix):
    #     prefix.extend([html.p("foo: bar")])
    
    def pytest_configure(config):
        config._metadata['测试人员'] = 'emily' #添加环境项
    
    runtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    
    print(runtime)
    
    def pytest_html_results_table_header(cells):
        cells.insert(0, html.th('用例编号'))
        cells.insert(1, html.th('所属模块'))
        cells.insert(2, html.th('用例名称'))
        cells.insert(3, html.th('接口路径'))
        cells.insert(5, html.th('执行时间', class_='sortable time', col='time'))
        cells.pop(6)
        cells.pop()
    
    def pytest_html_results_table_row(report, cells):
        url = 'http://xxx.com'
        testnode = report.nodeid.encode("utf-8").decode("unicode_escape")  #获取测试节点(测试数据格式列表中有元祖,元祖有列表)
        caseid = testnode.split('-')[3]  #获取测试节点中的部分内容
        cells.insert(0, html.td(caseid))
        module = testnode.split('-')[2]
        cells.insert(1, html.td(module))
        casename = testnode.split('-')[1]
        url = url+testnode.split('-')[4][:-1]
        cells.insert(2, html.td(casename))
        cells.insert(3, html.td(url))
        cells.insert(5, html.td(runtime, class_='col-time'))
    
        cells.pop(6)
        cells.pop()
    
    @pytest.hookimpl(hookwrapper=True)
    def pytest_runtest_makereport(item, call):
        outcome = yield
        report = outcome.get_result()
        # report.casename = str(item.function.__code__.co_varnames) #获取方法参数名
        # report.casename = str(item.node_id)

    报告如下:

     测试数据:

  • 相关阅读:
    机器学习:逻辑回归(基础理解)
    机器学习:模型泛化(L1、L2 和弹性网络)
    机器学习:模型泛化(LASSO 回归)
    机器学习:模型泛化(岭回归:Ridge Regression)
    Numpy:np.random 的使用
    ASP.NET MVC 视图层-生成链接相关(Html.ActionLink,Url.Action)
    eval实例
    <a>实现按钮的javascript+jquery编程实例
    SQL Server之XML PATH()
    分页数算法
  • 原文地址:https://www.cnblogs.com/lelexiong/p/13953737.html
Copyright © 2020-2023  润新知