1.环境搭建
(1)下载并解压allure.zip,不要用中文路径,将bin目录配置到path环境变量
官网:Allure下载
(2)cmd安装allure-pytest第三方库
pip install allure-pytest
检测是否安装成功
pip show allure-pytest
(3)安装JDK环境
(4)把pycharm的bin目录添加到环境变量
2.代码演示
import pytest,os,allurelist=[[1,2],[2,3],[3,5],[6,6]]
# 使用装饰器,只需要设置列表的值即可
class Test1:@pytest.mark.parametrize('expected_result,actual_result',list)def test_c100(self,expected_result,actual_result):assert expected_result==actual_result@pytest.mark.parametrize('x,y,z',[[1,2,3],[4,5,6]])def test_c101(self,x,y,z):assert x+y==z
if __name__ == '__main__':#--alluredir:allure路径#./report/report生成报告的路径#--clean-alluredir如果有旧数据,需要清除pytest.main([__file__,'-sv','--alluredir','./report/report','--clean-alluredir'])os.system('allure serve ./report/report')
报告结果:
3.Allure层级
(1)第一层:项目层@allure.epic
(2)第二层:模块层@allure.feature
(3)第三层:接口层@allure.story
(4)第四层:用例层@allure.title
3.1 代码演示
import pytest,os,allure
# -*- coding: utf-8 -*-@allure.epic('项目名称')
@allure.feature('业务模块名称')
class Test1:@allure.story('接口名称1')@allure.title('用例标题1')def test_c01(self):assert 1==2@allure.story('接口名称2')@allure.title('用例标题2')def test_c02(self):assert 2==3
if __name__ == '__main__':pytest.main([__file__,'-sv','--alluredir','./report/report','--clean-alluredir'])os.system('allure serve ./report/report')