zoukankan      html  css  js  c++  java
  • 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)

    报告如下:

     测试数据:

  • 相关阅读:
    临时
    vue数据立刻绑定到dom元素
    java浅拷贝和深拷贝(基础也是很重要的)
    Eclipse快捷键大全
    微信小程序开发之路之组件化
    c++入门笔记
    开发个活动上线是个什么体验
    分布式锁的理解,java自带的锁为什么会失效
    vue页面开发遇到的坑,都是泪!src属性,freemarker取值
    java泛型理解。代码更明了。
  • 原文地址:https://www.cnblogs.com/lelexiong/p/13953737.html
Copyright © 2011-2022 走看看