遇一山,过一山,处处有风景;只要勇敢向前,一路尽是繁花盛开。 | (点击查看→)【测试干货】python/java自动化、持续集成、性能、测开、简历、笔试面试等

pytest简易教程(35):pytest常用插件 - allure报告(allure-pytest)

 

pytest简易教程汇总,详见https://www.cnblogs.com/uncleyong/p/17982846

简介

Allure是一款java语言开发的轻量级开源自动化测试报告生成框架;

它支持绝大部分测试框架,比如TestNG、Junit、pytest等;

可以提供详尽的的测试报告内容;

也可以为管理理层提供high level统计报告;

可以集成到Jenkins。

 

官网:https://allurereport.org/

pytest:https://allurereport.org/docs/pytest/

 

安装、配置

1、allure应用安装、配置

参考:https://www.cnblogs.com/uncleyong/p/16726826.html,windows下安装配置

 

2、allure插件安装

pip install allure-pytest

 

常用命令

运行测试用例并收集结果:pytest -s -q --alluredir=${WORKSPACE}/result --clean-alluredir

查看报告方式一:

  • 查看在线测试报告:allure server ./result

查看报告方式二:

  • 生成最终测试报告:allure generate ./result --clean

  • 打开生成的最终测试报告:allure open ./allure-report

 

演示:生成allure报告

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 韧
# @wx :ren168632201
# @Blog :https://www.cnblogs.com/uncleyong/
 
 
def test_a():
    print("---test_a")
    assert 1 == 2
 
def test_b():
    print("---test_b")
    assert 1==1
class Test01:
    def test_d(self):
        print("---test_d")
        assert False
 
    def test_c(self):
        print("---test_c")
        assert "cs" in "qzcsbj"

  

运行测试用例并收集结果

pytest case\test_qzcsbj.py -s -q --alluredir=./result --clean-alluredir

 

查看报告方式一

allure serve ./result

 

报告

 

查看报告方式二

生成最终测试报告:allure generate ./result --clean

生成了allure-report目录

打开生成的最终测试报告:allure open ./allure-report

报告

 

allure报告结构

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 韧
# @wx :ren168632201
# @Blog :https://www.cnblogs.com/uncleyong/
 
import pytest
 
class Test01:
    def test_success(self):
        assert 1==1
 
    def test_fail(self):
        assert 1==2
 
def test_skip():
    pytest.skip("---skip")
 
@pytest.mark.xfail(1==1, reason="---xfail")
def test_xfail():
    # pytest.xfail("---xfail")
    1==2
 
def test_broken():
    raise Exception("---exception")
 
def test_error():
    assert a=="qzcsbj"

  

运行:pytest case\test_qzcsbj.py -vs --alluredir ./result --clean-alluredir

 

打开报告:allure serve ./result/

 

切换为中文

 

Overview:总览,包含用例数、各种结果统计、SUITES等

 

Categories:类别,默认情况下,有两类缺陷:

  • Product defects,测试结果:failed
  • Test defects,测试结果:error/broken

 

Suites:测试套件,所有用例的层级关系,可以根据package、module、类、方法、函数来查找用例

 

Graphs:测试结果图形化,包括用例执行结果的比例,不同优先级(severity)测试用例运行的统计数据,耗时等

 

Timeline:测试用例的执行顺序及执行时间

 

Behaviors:行为驱动,根据epic、feature、story来对测试用例分组,下图暂未分组默认显示测试用例函数名/方法名,下一篇分享

 

Packages:按照package、module来分组测试用例

 

补充:固件展示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 韧
# @wx :ren168632201
# @Blog :https://www.cnblogs.com/uncleyong/
import pytest
 
 
@pytest.fixture()
def login():
    print("---前置:登录")
    yield
    print("---后置:退出")
 
 
def test_a(login):
    print("--------------test_a")

  

结果:

 

【bak】

 

 

posted @   全栈测试笔记  阅读(425)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
浏览器标题切换
浏览器标题切换end
点击右上角即可分享
微信分享提示