pytest用例执行完成后自动生成allure测试报告

requset : 对于一个TestCase类,执行完成所有用例后,自动生成allure报告。对于单个用例,个人觉得直接在输出台查看结果即可。

step1:新建两个文件夹,result用来存放临时的json文件,report存放html报告

step2:pytest.ini命令行参数可以采用如下配置:

[pytest]
addopts = -vs --alluredir ../result

step3:conftest中设置fixture,目的是当所有用例执行完成后生成allure报告,并清理result下面的json文件

@pytest.fixture(scope="class")
def allure_report(request):
    def clear_result():
      print("所有用例执行完毕")
      os.system("allure generate {} -o {} --clean".format(result_path, report_path))
      print("allure报告已生成")
      # 当allure报告生成后,将result中的json文件清空
      for i in os.listdir(result_path):
         file_data = result_path + "\\" + i
         if os.path.isfile(file_data):
            os.remove(file_data)
      print("result下的json文件已清空")
    request.addfinalizer(clear_result)

Note:对于涉及到reruns的情况,可以注释掉清理json文件代码

step4:使用fixture:

@pytest.mark.usefixtures("allue_report")
class TestCase():

step5:查看report下的html文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值