Pytest+Allure定制报告
前言:
最近在研究接口自动化的框架,好的测试报告在整个测试框架起到至关重要的部分。终于被我发现一个超好用的报告框架,不仅报告美观,而且方便CI集成。
就是它,就是它:Allure Test Report!!!
先上一张报告效果图:
python版本及必要库
python 3.5
pytest 3.3.3
pytest-allure-adaptor 1.7.9
一、环境配置
安装Python依赖库:
pip3 install pytest
pip3 install pytest-allure-adaptor
安装 Command Tool:
brew tap qatools/formulas
brew install allure-commandline
官方参考文档:https://pypi.org/project/pytest-allure-adaptor/
二、生成html报告命令
1、pytest命令基础上加--alluredir,生成xml报告。
pytest -s -q --alluredir [xml_report_path]
//[xml_report_path]根据自己需要定义文件夹,作者定义为:/report/xml
用例执行完成之后会在[xml_report_path]目录下生成了一堆xml的report文件,当然这不是我们最终想要的美观报告。
2、需要使用 Command Tool 来生成我们需要的美观报告。
allure generate [xml_report_path] -o [html_report_path]
//[html_report_path]根据自己需要定义文件夹,作者定义为:/report/html
打开 index.html,之前写的 case 报告就会呈现在你面前
注⚠️:直接用chrome浏览器打开报告,报告可能会是空白页面。
解决办法:
1、在pycharm中右击index.html选择打开方式Open in Browser就可以了。
2、使用Firefox直接打开index.html。
三、定制报告
Feature: 标注主要功能模块
Story: 标注Features功能模块下的分支功能
Severity: 标注测试用例的重要级别
Step: 标注测试用例的重要步骤
Issue和TestCase: 标注Issue、Case,可加入URL
1、Features定制详解
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@allure.feature('test_module_01')
def test_case_01():
"""
用例描述:Test case 01
"""
assert 0
@allure.feature('test_module_02')
def test_case_02():
"""
用例描述:Test case 02
"""
assert 0 == 0
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
添加feature,Report展示见下图。
2、Story定制详解
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@allure.feature('test_module_01')
@allure.story('test_story_01')
def test_case_01():
"""
用例描述:Test case 01
"""
assert 0
@allure.feature('test_module_01')
@allure.story('test_story_02')
def test_case_02():
"""
用例描述:Test case 02
"""
assert 0 == 0
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
添加story,Report展示见下图。
3、用例标题和用例描述定制详解
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@allure.feature('test_module_01')
@allure.story('test_story_01')
#test_case_01为用例title
def test_case_01():
"""
用例描述:这是用例描述,Test case 01,描述本人
"""
#注释为用例描述
assert 0
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
添加用例标题和用例描述,Report展示见下图。
4 、Severity定制详解
Allure中对严重级别的定义:
1、 Blocker级别:中断缺陷(客户端程序无响应,无法执行下一步操作)
2、 Critical级别:临界缺陷( 功能点缺失)
3、 Normal级别:普通缺陷(数值计算错误)
4、 Minor级别:次要缺陷(界面错误与UI需求不符)
5、 Trivial级别:轻微缺陷(必输项无提示,或者提示不规范)
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@allure.feature('test_module_01')
@allure.story('test_story_01')
@allure.severity('blocker')
def test_case_01():
"""
用例描述:Test case 01
"""
assert 0
@allure.feature('test_module_01')
@allure.story('test_story_01')
@allure.severity('critical')
def test_case_02():
"""
用例描述:Test case 02
"""
assert 0 == 0
@allure.feature('test_module_01')
@allure.story('test_story_02')
@allure.severity('normal')
def test_case_03():
"""
用例描述:Test case 03
"""
assert 0
@allure.feature('test_module_01')
@allure.story('test_story_02')
@allure.severity('minor')
def test_case_04():
"""
用例描述:Test case 04
"""
assert 0 == 0
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
添加Severity,Report展示见下图。
5、Step定制详解
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@allure.step("字符串相加:{0},{1}")
# 测试步骤,可通过format机制自动获取函数参数
def str_add(str1, str2):
if not isinstance(str1, str):
return "%s is not a string" % str1
if not isinstance(str2, str):
return "%s is not a string" % str2
return str1 + str2
@allure.feature('test_module_01')
@allure.story('test_story_01')
@allure.severity('blocker')
def test_case():
str1 = 'hello'
str2 = 'world'
assert str_add(str1, str2) == 'helloworld'
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
添加Step,Report展示见下图。
6、Issue和TestCase定制详解
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@allure.step("字符串相加:{0},{1}") # 测试步骤,可通过format机制自动获取函数参数
def str_add(str1, str2):
print('hello')
if not isinstance(str1, str):
return "%s is not a string" % str1
if not isinstance(str2, str):
return "%s is not a string" % str2
return str1 + str2
@allure.feature('test_module_01')
@allure.story('test_story_01')
@allure.severity('blocker')
@allure.issue("http://www.baidu.com")
@allure.testcase("http://www.testlink.com")
def test_case():
str1 = 'hello'
str2 = 'world'
assert str_add(str1, str2) == 'helloworld'
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
添加Issue和TestCase,Report展示见下图。
8、attach定制详解
file = open('../test.png', 'rb').read()
allure.attach('test_img', file, allure.attach_type.PNG)
在报告中增加附件:
allure.attach(’arg1’,’arg2’,’arg3’):
arg1
:是在报告中显示的附件名称
arg2
:表示添加附件的内容
arg3
:表示添加的类型(支持:HTML,JPG,PNG,JSON,OTHER,TEXTXML
)
添加attach参数,Report展示见下图。
此外,Allure还支持Jenkins Plugin,后面我会专门写一篇博文介绍,感兴趣的话请关注我的个人简书。
以上,对你有帮助的话,点赞吧❤️~~
Pytest+Allure定制报告的更多相关文章
- 【Mac+Wind7】pytest + allure生成定制报告
一.升级Powershell(windows7及以上版本默认自带.其实普通的CMD命令行工具够用了) 我是Win7默认带的pw1.0,太古老了升级一下,地址如下,选择与自己windows版本匹配的连接 ...
- pytest+allure(allure-pytest基于这个插件)设计定制化报告
一:环境准备 1.python3.6 2.windows环境 3.pycharm 4.allure-pytest 5.allure2.8.0 6.java1.8 allure-pytest快速安装 在 ...
- pytest+allure(pytest-allure-adaptor基于这个插件)设计定制化报告
一:环境准备 1.python3.6 2.windows环境 3.pycharm 4.pytest-allure-adaptor 5.allure2.8.0 6.java1.8 pytest-allu ...
- 手把手教你Pytest+Allure2.X定制报告详细教程,给自己的项目量身打造一套测试报告-02(非常详细,非常实用)
简介 前边一篇文章是分享如何搭建pytest+Allure的环境,从而生成一份精美的.让人耳目一新的测试报告,但是有的小伙伴或者童鞋们可能会问,我能不能按照自己的想法为我的项目测试结果量身打造一份属于 ...
- allure定制化输出测试报告,让报告锦上添花!
一.定制化后的效果展示 用两张图展示效果: 二.注意别踩坑 allure定制化想必大部分情况都会去选择pip install pytest-allure-adaptor这个插件,安装完成后,运行定制化 ...
- pytest+allure测试框架搭建
https://blog.csdn.net/wust_lh/article/details/86685912 https://www.jianshu.com/p/9673b2aeb0d3 定制化展示数 ...
- appium+pytest+allure+jenkins 如何实现多台手机连接
使用appium可以实现app自动化测试,我们之前是连接一台手机去运行,如何同时连接多台手机呢?很多人可能想到的是多线程(threading).今天分享一种比多线程更简单的方法,虽然不是多台手机同时运 ...
- pytest使用笔记(三)——pytest+allure+jenkins配置使用
按照pytest使用笔记(二)把pytest+allure配置好后,现在在jenkins配置好,先实现手动构建(立个小目标) 一,安装jenkins插件 首页->系统管理->插件管理,从“ ...
- pytest + allure + jenkins 生成漂亮的测试报告
pytest我在上一篇文章初始pytest中已有介绍,是一个很理想的Python测试框架.Allure是一款非常轻量级并且非常灵活的开源测试报告生成框架. 它支持绝大多数测试框架, 例如TestNG. ...
随机推荐
- [20180927]ora-01426.txt
[20180927]ora-01426.txt --//链接:http://www.itpub.net/thread-2105458-1-1.html1.环境:SCOTT@test01p> @ ...
- sql语句中的join用法(可视化解释)
一.innerjoin innerjoin总结来说就是 ,如A知道通往B如何走:B知道通往C如何走:但是A不知道通往C如何走,但是A可以通过B获得去往C的通往方式.. 首先,假设有A,B两张表,结构及 ...
- python爬虫之天气预报网站--查看最近(15天)的天气信息(正则表达式)
python爬虫之天气预报网站--查看最近(15天)的天气信息(正则表达式) 思路: 1.首先找到一个自己想要查看天气预报的网站,选择自己想查看的地方,查看天气(例:http://www.tianqi ...
- windows平台下实现高可用性和可扩展性-ARR和HLB
本文档提供了关于如何将应用程序请求路由(ARR)与硬件负载均衡器一起使用以实现高可用性和可伸缩性的说明性指导.本文采用F5大IP负载均衡器来说明ARR与硬件负载平衡器之间的工作关系. IIS7.0及以 ...
- 如何激活windows或office
郑重承诺:该激活软件没有病毒,有任何侵害行为,找我QQ:122317653 Step one: 首先你需要安装KMS Auto Net激活器,但我们都知道一些杀毒软件都会将此类激活器警告成木马病毒,原 ...
- flex布局大讲解
http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_source=tuicool
- centos6.5下配置django+uwsgi+nginx
https://blog.csdn.net/huanbia/article/details/54630180
- centos7下安装docker(24docker swarm 数据管理)
service的容器副本会scal up/down,会failover,会在不同的主机上创建和销毁,这就引出一个问题,如果service有数据,那么这些数据该如何存放呢? 1.打包在容器中: 显然不行 ...
- 51nod 省选联测 R2
51nod 省选联测 R2 上场的题我到现在一道都没A,等哪天改完了再写题解吧,现在直接写第二场的. 第二场比第一场简单很多(然而这并不妨碍我不会做). A.抽卡大赛:http://www.51nod ...
- ②---Java开发工具Eclipse安装配置
Java开发工具Eclipse安装及配置 以下将为大家介绍Java开发工具Eclipse安装及配置. 一.下载Eclipse安装文件 正所谓工欲善其事必先利其器,我们在开发java语言过程中同样需要依 ...