python pytest allure_python-pytest-Allure2测试报告生成

本文介绍了如何在Python环境下使用pytest和allure框架生成详细的测试报告。包括安装环境,如JDK1.8,使用pip安装allure-pytest,以及如何通过allure的各种注解来丰富测试报告内容,如描述、步骤、等级、附件等。同时,还展示了如何添加环境信息、自定义测试结果分类,并提供了pytest执行并生成allure报告的命令。
摘要由CSDN通过智能技术生成

Allure:

Allure框架是一种灵活的轻量级多语言测试报告工具,它以简洁的web报告形式显示已测试的内容。

安装环境(win10):

安装JDK1.8+环境:

Allure需要java8+,JDK 1.8+ 环境,所以要提前配置好java环境。

官方下载地址:https://www.oracle.com/java/technologies/javase-jdk8-downloads.html,1.8后的jdk会自动添加环境变量

安装allure命令:

pip install allure-pytest

安装完成会提示:Installing collected packages: allure-python-commons, allure-pytest

Successfully installed allure-pytest-2.8.13 allure-python-commons-2.8.13

allure用例描述:

allure.epic("xxx") ----------------> 参数:敏捷测试中的概念 史诗,可以理解为项目级别的描述

allure.feature("xxx") ------------>  参数:模块描述,功能点描述

allure.stroy("xxx") --------------->  参数:用例描述,用例故事

allure.title("xxx") -----------------> 参数:用例重命名的标题,显示报告中,不重命名则显示函数/方法名

allure.step("xxx") ----------------> 参数:测试步骤的描述

allure.description("xxx") -------> 参数:测试用例描述

allure.severity("xxx") -----------> 参数:用例等级(blocker、critical、normal、minor、trivial)

allure.attachment("xxx") ------> 参数:报告中添加的附件

allure.testcase("xxx") ----------> 参数:功能测试用例链接地址

allure.issue("xxx") --------------> 参数:缺陷链接地址

allure.link("xxx") -----------------> 参数:定义一个链接,显示在报告中

添加environment:

通过创建environment.properties或者environment.xml文件,并把文件存放到报告依赖文件的同级目录下,就是--alluredir 后面跟的目录

#environment.xml文件如下:

Browser

Chrome

#environment.properties文件内容

Browser =Chrome

python.Version= 3.7.2

添加categories:

分类:测试结果的分类,默认两类缺陷

1. Product defects 产品缺陷 (测试结果failed)

2. Test defects 测试缺陷 (测试结果:error/broken)

我们可以自定义缺陷,将categories.json 文件添加到 报告文件存放的目录

#官方例子 categories.json

[

{"name": "Ignored tests","matchedStatuses": ["skipped"]

},

{"name": "Infrastructure problems","matchedStatuses": ["broken", "failed"],"messageRegex": ".*bye-bye.*"},

{"name": "Outdated tests","matchedStatuses": ["broken"],"traceRegex": ".*FileNotFoundException.*"},

{"name": "Product defects","matchedStatuses": ["failed"]

},

{"name": "Test defects","matchedStatuses": ["broken"]

}

]

官方字段解释:

name: (mandatory) category name

matchedStatuses:(optional) list of suitable test statuses. Default ["failed", "broken", "passed", "skipped", "unknown"]

messageRegex: (optional) regex pattern to check test error message. Default".*"traceRegex: (optional) regex pattern to check stack trace. Default".*"

pytest 执行并生成报告的过程:

pytest --alluredir ./report/allure_raw

执行完成后,在当前目录下,report目录会生成一个allure_raw的原始文件,这个只是测试报告的原始文件,不能打开成html的报告。

allure serve report/allure_raw

启动服务,它会自动给个端口,直接用默认浏览器打开了,也可以手动复制地址在其他浏览器中打开。

指定执行用例:

pytest --alluredir ./report/allure --allure-epics="epic的描述信息"pytest--alluredir ./report/allure --allure-features="feature描述"pytest--alluredir ./report/allure --allure-stories="story描述"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值