allure的安装使用以及报告的生成

详细见此篇博客:https://www.cnblogs.com/yoyoketang/p/12203778.html
allure的几种方法:
allure用例描述
使用方法 参数值 参数说明
@allure.epic() epic描述 敏捷里面的概念,定义史诗,往下是feature
@allure.feature() 模块名称 功能点的描述,往下是story
@allure.story() 用户故事 用户故事,往下是title
@allure.title(用例的标题) 用例的标题 重命名html报告名称
@allure.testcase() 测试用例的链接地址 对应功能测试用例系统里面的case
@allure.issue() 缺陷 对应缺陷管理系统里面的链接
@allure.description() 用例描述 测试用例的描述
@allure.step() 操作步骤 测试用例的步骤
@allure.severity() 用例等级 blocker,critical,normal,minor,trivial
@allure.link() 链接 定义一个链接,在测试报告展现
@allure.attachment() 附件 报告添加附件

例如:
在这里插入图片描述
生成的报告如下:
在这里插入图片描述
因此层级结构为:epic—>feature—>story—>title

当我们最终执行用例的时候,是在jenkins上构建job执行测试用例,即Gitlab-->jenkins-->job
什么时候执行(回归、冒烟测试)
一般流程:新的代码(版本)提交-->部署接口-->构建job--》冒烟/回归测试报告--》邮件通过
pytest allure的安装豆瓣地址
pip install pytest==5.4.3 --index-url https://pypi.douban.com/simple
pip install allure-pytest==2.8.6 --index-url https://pypi.douban.com/simple
allure是一个命令行工具,需要去github 上下载最新版https://github.com/allure-framework/allure2/releases
# pytest --alluredir=./report/allure --allure-severities=normal
import allure
@allure.epic("OA系统测试接口")
@allure.feature("测试模块1")
class Test():
    @allure.severity('normal') # 用例等级
    # @allure.title('新增单据')
    @allure.issue('http://www.baidu.com')
    @allure.story('新增单据')
    @allure.step('新增')
    def test_01(self):
        print('新增')

    @allure.story('新增单据')
    @allure.step('保存')
    def test_02(self):
        print('保存')

1、执行以下命令输出allure报告

pytest --alluredir ./report/allure_raw 指定测试报告存放路径
./report/allure_raw当前目录下report文件下的report/allure_raw


D:\code\py_dev_test\pytest框架\pytest_base\allure报告>pytest --alluredir ./report/allu
re_raw
================================ test session starts ================================
platform win32 -- Python 3.6.0, pytest-4.5.0, py-1.8.0, pluggy-0.13.1
rootdir: D:\code\py_dev_test\pytest框架\pytest_base\allure报告, inifile: pytest.ini
plugins: allure-pytest-2.8.6, base-url-1.4.2, html-1.19.0, metadata-1.8.0
collected 2 items                                                                    

test_allure.py ..                                                              [100%]

============================= 2 passed in 0.42 seconds ==============================

即生成一个原始文件的报告
在这里插入图片描述

2、执行以下命令生成可视化页面报告

allure serve report/allure_raw

D:\code\py_dev_test\pytest框架\pytest_base\allure报告>allure serve report/allure_raw
Generating report to temp directory...
report\allure_rawlure_raw does not exists
Report successfully generated to C:\Users\ADMINI~1\AppData\Local\Temp\9181726724528405
272\allure-report
Starting web server...
2021-08-31 21:52:17.536:INFO::main: Logging initialized @9647ms to org.eclipse.jetty.u
til.log.StdErrLog
Server started at <http://192.168.1.101:58436/>. Press <Ctrl+C> to exit

打开上面的地址即可看到报告详情
在这里插入图片描述

3、allure命令行参数

  • 根据epic属性执行用例:

pytest --alluredir ./report/allure --allure-epics=OA系统测试接口

D:\code\py_dev_test\pytest框架\pytest_base\allure报告>pytest --alluredir ./report/allure --allure-epics=OA系统测试接口
===================================================== test session starts ======================================================
platform win32 -- Python 3.6.0, pytest-4.5.0, py-1.8.0, pluggy-0.13.1
rootdir: D:\code\py_dev_test\pytest框架\pytest_base\allure报告, inifile: pytest.ini
plugins: allure-pytest-2.8.6, base-url-1.4.2, html-1.19.0, metadata-1.8.0
collected 2 items                                                                                                               

test_allure.py ..                                                                                                         [100%]

=================================================== 2 passed in 0.33 seconds ===================================================

根据featires执行:pytest --alluredir ./report/allure --allure-features=测试模块1 (=号后面是features的名称)

D:\code\py_dev_test\pytest框架\pytest_base\allure报告>pytest --alluredir ./report/allure --allure-features=测试模块1
===================================================== test session starts ======================================================
platform win32 -- Python 3.6.0, pytest-4.5.0, py-1.8.0, pluggy-0.13.1
rootdir: D:\code\py_dev_test\pytest框架\pytest_base\allure报告, inifile: pytest.ini
plugins: allure-pytest-2.8.6, base-url-1.4.2, html-1.19.0, metadata-1.8.0
collected 2 items                                                                                                               

test_allure.py ..                                                                                                         [100%]

=================================================== 2 passed in 0.07 seconds ===================================================

  • 根据story执行用例:

pytest --alluredir ./report/allure --allure-stories=新增单据 (stories=story名称)

D:\code\py_dev_test\pytest框架\pytest_base\allure报告>pytest --alluredir ./report/allure --allure-stories=新增单据
===================================================== test session starts ======================================================
platform win32 -- Python 3.6.0, pytest-4.5.0, py-1.8.0, pluggy-0.13.1
rootdir: D:\code\py_dev_test\pytest框架\pytest_base\allure报告, inifile: pytest.ini
plugins: allure-pytest-2.8.6, base-url-1.4.2, html-1.19.0, metadata-1.8.0
collected 2 items                                                                                                               

test_allure.py ..                                                                                                         [100%]

=================================================== 2 passed in 0.12 seconds ===================================================

  • 根据用例等级执行用例:

pytest --alluredir ./report/allure --allure-severities=normal (normal 为等级)

allure中对等级划分为以下几个等级:
blocker:阻塞缺陷
critical:严重缺陷
normal:一般缺陷
minor:次要缺陷
trivial:轻微缺陷

在这里插入图片描述
在这里插入图片描述

执行:pytest --alluredir ./report/allure --allure-severities=normal

D:\code\py_dev_test\pytest框架\pytest_base\allure报告>pytest --alluredir ./report/allu
re --allure-severities=normal
================================ test session starts ================================
platform win32 -- Python 3.6.0, pytest-4.5.0, py-1.8.0, pluggy-0.13.1
rootdir: D:\code\py_dev_test\pytest框架\pytest_base\allure报告, inifile: pytest.ini
plugins: allure-pytest-2.8.6, base-url-1.4.2, html-1.19.0, metadata-1.8.0
collected 2 items                                                                    

test_allure.py .                                                               [100%]

============================= 1 passed in 0.08 seconds =========================
  • 在执行前清空之前已生成的报告:
    pytest --alluredir ./report/allure --clean-alluredir

我们可以将以上这些以pytest的命令加到配置文件中,执行的时候就会自动带上。如果有多个命令,中间以空格间隔开。
在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值