Pytest之allure报告生成

准备条件:

  1. 安装 Allure 并配置环境变量 https://github.com/allure-framework/allure2/releases

  1. import allure

报告生成:

  1. 结合pytest框架生成allure报告

if __name__ == '__main__':
    import pytest
    import os

    pytest.main(['-vs', './test_case_api/test.py', '--alluredir=../tmp/allure-results', '../tmp/allure-results'])
    os.system("allure generate ../tmp/allure-results -o ../tmp/html --clean")

生成json文件的固定写法:

pytest.main(['-vs',用例脚本文件路径,指定alluredir路径,生成json报告存放路径])

输出json文件为html文件固定写法:

os.system("allure generate json文件存放路径 -o html文件存放路径 --clean")

  1. 函数标记装饰器

函数标记装饰器,可以同步展示到测试报告内(函数才能使用)

@allure.epic 史诗->系统

@allure.feature 模块

@allure.story 故事

@allure.title 标题

@allure.step 步骤

@allure.feature("xx模块")
class Test_100(unittest.TestCase):
    @allure.story("用户中心")
    @allure.title('新增用户')
    def test_01(self):
        with allure.step("新增"):

生成报告效果如下:

1、在展示层级上,epic包含feature,feature包含story,story包含title,title包含step

2、它们可以同时使用,也可以单独使用,也可以不使用

  1. 标记方式都支持汉字

with allure.step()在python脚本中都可以使用,是代码块形式

with allure.step():

print("第一步")

    def wait(self, assert_sql, value):
        assert_sql = Template(assert_sql).substitute(goods=Argument.goods)
        sql_connect = Sql()
        result = sql_connect.execute(assert_sql).fetchone()
        with allure.step("当状态为空时,等待3s"):
            while not result:
                result = sql_connect.execute(assert_sql).fetchone()
                time.sleep(3)
        with allure.step("当状态不为空时,判断状态值"):
            while result:
                time.sleep(3)
                result = sql_connect.execute(assert_sql).fetchone()
                if result[0] == int(value):
                    with allure.step("成功"):
                        break
                else:
                    with allure.step("循环等待3s"):
                        continue

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值