Allure测试报告

allure安装

Mac安装方式
1
brew install allure
2 pip install allure-pytest
Windows安装方式
1
https://github.com/allure-framework/allure2/releases 2 下载解压后将allure.bat添加进系统环境变量中
3 pip install allure-pytest

allure特性分析

 代码示例:


import allure
import pytest

@allure.feature("计算器")  
@allure.testcase("https://www.baidu.com/")
class TestCalc:
    @allure.story("加法")
    @allure.title("加法测试")
    @allure.testcase("https://jiafa.com/test_case")
    def test_add(self):
        with allure.step("3+5的和"):
            result = 3 + 5
            assert result == 8
       
        with allure.step("2+8的和"):
            result = 2 + 8
            assert result == 10
           
    @allure.story("减法")
    @allure.title("减法测试")
    def test_subtract(self):
        with allure.step("计算两个数的差"):
            result = 5 - 3
            assert result == 2

 allure报告中嵌入文本、图片、视频

 1 import allure
 2 import pytest
 3 """
 4 以下两个可以放在 类或方法上都行,但是也有区别
 5 allure.testcase: 如果类和方法上都有,在方法上显示两个链接
 6 allure.severity: 如果类和方法上都有,在线报告中会显示方法中的分级
 7 """
 8 
 9 @allure.feature("计算器")  # 定义功能
10 @allure.testcase("https://www.baidu.com/")  # 定义测试用例的链接地址
11 # @allure.severity(allure.severity_level.CRITICAL)  # 定义用例等级
12 class TestCalc:
13     @allure.story("加法")   # 定义用户场景
14     @allure.title("加法测试")   # 定义测试用例的标题
15     @allure.testcase("https://jiafa.com/test_case") # 定义测试用例的链接地址
16     @allure.severity(allure.severity_level.CRITICAL)  # 定义用例等级
17     @pytest.mark.parametrize("a, b, expected", [(1, 2, 3), (3, 4, 7), (5, 6, 11)])  # 定义测试数据
18     def test_add(self,a, b, expected):
19         with allure.step(f"{a} + {b} = {expected}"):    # 定义测试步骤
20             result = a + b
21             assert result == expected
22         
23             
24     @allure.story("减法")
25     @allure.title("减法测试")
26     @allure.severity(allure.severity_level.MINOR)
27     def test_subtract(self):
28         with allure.step("计算两个数的差"):
29             result = 5 - 3
30             assert result == 2
31     
32     @allure.story("乘法")
33     @allure.title("乘法测试")
34     @allure.severity(allure.severity_level.CRITICAL)
35     def test_multiply(self):
36         with allure.step("计算两个数的积"):
37             result = 2 * 3
38             assert result == 6
39 
40 class TestCalc2:
41     @allure.story("除法测试")
42     @allure.title("整数相除")
43     @allure.severity(allure.severity_level.MINOR)
44     def test_divide(self):
45         with allure.step("计算两个整数相除的商"):
46             result = 10 / 2
47             assert result == 5
48             allure.attach("朝朝暮暮生死相依", "这是描述", allure.attachment_type.TEXT)  # 在步骤中添加文本信息
49             allure.attach("<head><body>受益人</body></head>", "这是HTML", allure.attachment_type.HTML)  # 在步骤中添加HTML
50             
51     @allure.story("除以0测试")
52     @allure.title("被除数为0")
53     @allure.severity(allure.severity_level.CRITICAL)
54     def test_divide_by_zero(self):
55         with allure.step("计算被除数为0的商"):
56             result = 20 / 10
57             assert result == 2
58             # 在步骤中添加截图
59             allure.attach.file("C:\\Users\\love8\\Desktop\\web自动化多浏览器处理.png", name="图片", attachment_type=allure.attachment_type.PNG)
60             # 在步骤中添加视频
61             allure.attach.file("C:\\Users\\love8\\Downloads\\下次你乱买东西被骂,传这个给你另一半看.mp4",name="视频", attachment_type=allure.attachment_type.MP4)

如上,可以在本地运行一下看以下报告的内容

allure运行

报告展示

 

posted @ 2024-04-04 16:24  韩凯1202  阅读(27)  评论(0编辑  收藏  举报