1.allure安装
allure安装:pip install allure-pytest
官方文档:https://pypi.org/project/allure-pytest/
下载allure: https://github.com/allure-framework/allure2/releases
pytest依赖插件:pip install pytest-dependency
2.浏览器打开allure报告
浏览器使用一般使用firefox浏览器。
3.定制化标签
定制化标签如下:
@allure.epic("外卖系统")
@allure.feature("商铺模块")
@allure.tag("个人中心")
allure用例描述,参考博文:
import pytest
import allure
@allure.feature('功能点的描述,一级标签')
class TestAllure():
@allure.title('用例0')
@allure.story('用户故事,第一个二级标签')
@allure.title('用例1')
@allure.story('用户故事,第二个二级标签')
def test_allure(self):
allure.attach.file(r'E:\interface_cest_auto_0324\data\1.jpg','我是附件截图的文件',attachment_type='jpg')
@allure.title('用例2')
@allure.story('用户故事,第三个二级标签')
@allure.severity("critical")
@allure.description("测试用例的描述")
4.设置用例级别
critical、normal、blocker等等级级别。
执行用例命令
'pytest -sq --alluredir=../report/tmp --allure-severities=normal,critical'
@allure.severity("critical")
def test_01():
print("test case 001")
@allure.severity("normal")
def test_02():
print("test case 002")
@allure.severity("blocker")
def test_03():
print("test case 003")
def test_04():
print("test case 004")
5.设置allure显示环境
在allure报告中添加环境信息,通过创建environment.properties或者environment.xml文件,并把文字存放到allure-results(这个目录是生成最后的html报告之前,生成依赖文件的目录)目录下。
environment.properties
Browser=Firefox
Browser.Version=77
stand=teach
ApiUrl=127.0.0.1/login
python.version=3.9