7.接口自动化测试-Allure报告

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,allure

list=[[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')

在这里插入图片描述

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-12 14:28:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-12 14:28:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-12 14:28:01       82 阅读
  4. Python语言-面向对象

    2024-04-12 14:28:01       91 阅读

热门阅读

  1. 使用列表递推实现螺旋矩阵

    2024-04-12 14:28:01       34 阅读
  2. 如何通过子网掩码来计算IP的地址范围

    2024-04-12 14:28:01       30 阅读
  3. 【Spring高级】SpringMVC处理流程总结

    2024-04-12 14:28:01       39 阅读
  4. ffmpeg编解码opus注意事项

    2024-04-12 14:28:01       40 阅读
  5. 计算机网络——MAC地址和IP地址

    2024-04-12 14:28:01       37 阅读
  6. 汽车传动轴原理?

    2024-04-12 14:28:01       37 阅读
  7. RabbitMQ介绍

    2024-04-12 14:28:01       46 阅读