• pytest html


    conftest.py 编写灯具可以在testcases 用例直接引用项目目录和pytest.ini一致可以全局使用,其次每个包可以有自己的conftest.py
    import pytest
    import uuid
    import time
    from _pytest import runner

    @pytest.fixture(scope='session')
    def login():
    token = uuid.uuid1().hex
    return token

    @pytest.fixture()
    def get_order_list():

    return {"msg":'ok',"code":"200","data":[
    {"id":0,'order_sn':"03403-38439-48944"},
    {"id":1,'order_sn':"13403-38439-4894"}
    ]
    }

    @pytest.fixture()
    def get_order_detail():

    return {"id":3,'msg':200,"data":['this is detail ']}

    class Variable:
    def set(self,key,value):
    setattr(self,key,value)
    def get(self,key):
    return getattr(self,key)
    def has(self,key):
    return hasattr(self,key)

    varaible = Variable()


    # @pytest.hookimpl(hookwrapper=True, tryfirst=True)
    # def pytest_runtest_makereport(item, call):
    # print('------------------------------------')
    # # 获取钩子方法的调用结果
    # out = yield
    # # 3. 从钩子方法的调用结果中获取测试报告
    # res = out.get_result() # 获取用例执行结果
    # if res.when == "call": # 只获取call用例失败时的信息
    # print("func_name:{}".format(item.function.__name__))
    # print("description 用例描述:{}".format(item.function.__doc__))
    # print("exception异常:{}".format(call.excinfo))
    # print("exception详细日志:{}".format(res.longrepr))
    # print("nodeid:{}".format(res.nodeid))
    # print("outcome测试结果:{}".format(res.outcome))
    # print("duration用例耗时:{}".format(res.duration))
    # # print(res.__dict__)
    #
    # def pytest_terminal_summary(terminalreporter, exitstatus, config):
    # '''收集测试结果'''
    # tr = terminalreporter
    # dlist= []c'le
    # for replist in tr.stats.values():
    # for rep in replist:
    # if hasattr(rep, "duration"):
    # dlist.append({'dur':rep.duration,'seqno':rep.nodeid,
    # 'result':rep.outcome,'longtext':rep.longreprtext,
    # 'stderr':rep.capstderr,'keywords':rep.keywords})
    # #
    # # print("total:", terminalreporter._numcollected)
    # # print('passed:', len(terminalreporter.stats.get('passed', [])))
    # # print('failed:', len(terminalreporter.stats.get('failed', [])))
    # # print('error:', len(terminalreporter.stats.get('error', [])))
    # # print('skipped:', len(terminalreporter.stats.get('skipped', [])))
    # duration = time.time() - terminalreporter._sessionstarttime
    # print('total times:', duration, 'seconds')

     pytest --html=report.html --self-contained-html -v



  • 相关阅读:
    H3C IS-IS基础配置
    H3C OSPF实验大集合(IPv4)
    H3C OSPF实验大集合(IPv6)
    H3C RIP实验大集合
    H3C IPv4和IPv6负载均衡
    H3C IPv4与ipv6静态路由
    H3C 配置dns及arp
    H3C 配置DHCP服务器
    H3C 多生成树MSTP
    H3C 配置ftp服务器
  • 原文地址:https://www.cnblogs.com/SunshineKimi/p/16534185.html
Copyright © 2020-2023  润新知