allure简介

  Allure Framework是一个灵活的轻量级多语言测试报告工具。貌似是目前最漂亮的一个报告工具


python版本及必要库或工具

python 3.7

pytest 4.3.1

allure-pytest 2.6.1 (注意:这里不要使用pytest-allure-adaptor,踩过坑。使用pytest-allure-adaptor时因为一些兼容问题发现只有pytest3.7.0 才可以与alllure2.0匹配。但pytest3.7.0有不少bug)

command tool 工具 #用于生成美观报告

  brew tap qatools/formulas

  brew install allure-commandline


Features

1.title  case标题

  可以自定义用例标题,标题默认为函数名.

  @allure.title

# -*- coding: utf-8 -*-
# @Time : 2019/3/12 11:46
# @Author : zzt import allure
import pytest @allure.title("用例标题0")
def test_0():
pass @allure.title("用例标题1")
def test_1():
pass def test_2():
pass

执行效果:

  

2. 说明

  可以添加测试的详细说明,以便根据需要为报告阅读器提供尽可能多的上下文。

  两种方式:@allure.description 提供描述字符串的装饰器

       @allure.description_html 提供一些HTML在测试用例的描述部分  (待研究)

# -*- coding: utf-8 -*-
# @Time : 2019/3/12 11:46
# @Author : zzt import allure
import pytest @allure.title("用例标题0")
@allure.description("这里是对test_0用例的一些详细说明")
def test_0():
pass @allure.title("用例标题1")
def test_1():
pass @allure.title("用例标题2")
def test_2():
pass

  

3.  标签 

  这个标签非常好用

  @allure.feature   分组第一层

  @allure.story  分组第二层

  @allure.severity    标记严重级别

  用法一:通过@allure.feature  @allure.story来标记case 可以使得case在报告里显示更有层次感

# -*- coding: utf-8 -*-
# @Time : 2019/3/12 11:46
# @Author : zzt import allure
import pytest @allure.feature('这里是一级标签')
class TestAllure(): @allure.title("用例标题0")
@allure.description("这里是对test_0用例的一些详细说明")
@allure.story("这里是第一个二级标签")
def test_0(self):
pass @allure.title("用例标题1")
@allure.story("这里是第一个二级标签")
def test_1(self):
pass @allure.title("用例标题2")
@allure.story("这里是第二个二级标签")
def test_2(self):
pass

  运行结果如下:

  

  用法二:@allure.story @allure.feature 还可以用来指定执行的case集合

    1   --allure-features

    2   --allure-stories

    3   --allure-epics (待研究)

# -*- coding: utf-8 -*-
# @Time : 2019/3/12 11:46
# @Author : zzt import allure
import pytest @allure.feature('这里是一级标签')
class TestAllure(): @allure.title("用例标题0")
@allure.description("这里是对test_0用例的一些详细说明")
@allure.story("这里是第一个二级标签")
def test_0(self):
pass @allure.title("用例标题1")
@allure.story("这里是第二个二级标签")
def test_1(self):
pass @allure.title("用例标题2")
@allure.story("这里是第三个二级标签")
def test_2(self):
pass

  执行命令 pytest test_1.py --allure-stories "这里是第二个二级标签", "这里是第三个二级标签"               #

  执行结果如下:

  用法三:使用@allure.severity装饰器,  按严重性级别来标记case   这里等于给每个case定义一个严重级别  在Graphs页面查看分布情况。当然也可以指定执行的case集合  语法为 --allure.-severities XX,XX

  1. BLOCKER = 'blocker'  中断缺陷(客服端程序无响应,无法执行下一步骤)
  2. CRITICAL = 'critical'  临界缺陷(功能点缺失)
  3. NORMAL = 'normal'  普通缺陷(数据计算错误)
  4. MINOR = 'minor'  次要缺陷(界面错误与ui需求不符)
  5. TRIVIAL = 'trivial'  轻微缺陷(必须项无提示,或者提示不规范)  
# -*- coding: utf-8 -*-
# @Time : 2019/3/12 11:46
# @Author : zzt import allure
import pytest @allure.feature('这里是一级标签')
class TestAllure(): @allure.title("用例标题0")
@allure.description("这里是对test_0用例的一些详细说明")
@allure.story("这里是第一个二级标签")
@allure.severity(allure.severity_level.CRITICAL)
def test_0(self):
pass @allure.title("用例标题1")
@allure.story("这里是第二个二级标签")
@allure.severity(allure.severity_level.BLOCKER)
def test_1(self):
pass @allure.title("用例标题2")
@allure.story("这里是第三个二级标签")
@allure.severity(allure.severity_level.NORMAL)
def test_2(self):
pass

    执行结果如下:

     

4. step 步骤   为报告中对应case添加一些的描述,以提供更详细的操作步骤

  用法:@allure.step()

      @allure.step(‘这里是操作步骤的描述: 获取参数一:“{0}”,获取参数二: “{1}” ’)

      来装饰对应case

# -*- coding: utf-8 -*-
# @Time : 2019/3/12 11:46
# @Author : zzt import allure
import pytest @allure.feature('这里是一级标签')
class TestAllure(): @allure.title("用例标题0")
@allure.description("这里是对test_0用例的一些详细说明")
@allure.story("这里是第一个二级标签")
@allure.severity(allure.severity_level.CRITICAL)
@allure.step("这里是步骤说明一")
def test_0(self):
pass @allure.title("用例标题1")
@allure.story("这里是第二个二级标签")
@allure.severity(allure.severity_level.BLOCKER)
@allure.step("这里是步骤说明二")
def test_1(self):
pass @allure.step('这里是操作步骤打印:name: "{0}", age: "{age}"')
def step_with_title(self, name, age=10):
pass @allure.title("用例标题2")
@allure.story("这里是第三个二级标签")
@allure.severity(allure.severity_level.NORMAL)
def test_2(self):
self.step_with_title('张三')
self.step_with_title('李四', 20)
self.step_with_title('王五', age=30)

  执行结果如下:

  

5. 参数化

  可以将case所需参数展示在报告中,方便问题追踪

# -*- coding: utf-8 -*-
# @Time : 2019/3/12 11:46
# @Author : zzt import allure
import pytest @allure.feature('这里是一级标签')
class TestAllure(): @allure.title("用例标题0")
@allure.description("这里是对test_0用例的一些详细说明")
@allure.story("这里是第一个二级标签")
@allure.severity(allure.severity_level.CRITICAL)
@allure.step("这里是步骤说明一")
@pytest.mark.parametrize('param1, param2', [(1, 10), (2, 20)])
def test_0(self, param1, param2):
print(param1) @allure.title("用例标题1")
@allure.story("这里是第二个二级标签")
@allure.severity(allure.severity_level.BLOCKER)
@allure.step("这里是步骤说明二")
@pytest.mark.parametrize('param1', ['value 1', 'value 2'])
@pytest.mark.parametrize('param2', [True], ids=["这是一个有意思的操作"])
@pytest.mark.parametrize('param3', [1])
def test_1(self, param1, param2, param3):
pass @allure.step('这里是操作步骤打印:name: "{0}", age: "{age}"')
def step_with_title(self, name, age=10):
pass @allure.title("用例标题2")
@allure.story("这里是第三个二级标签")
@allure.severity(allure.severity_level.NORMAL)
def test_2(self):
self.step_with_title('张三')
self.step_with_title('李四', 20)
self.step_with_title('王五', age=30)

  执行结果如下:

6 附件

  报告可以展示许多不同类型的附件,用来补充测试,步骤等信息

  allure.attach(body, name, attachment_type, extension)

  1. body - 要写入文件的原始内容。

  2. name - 包含文件名的字符串

  3. attachment_type- 其中一个allure.attachment_type

  4. extension - 提供的将用作创建文件的扩展名

  或者 allure.attach.file(source, name, attachment_type, extension)

  source - 包含文件路径的字符串。

# -*- coding: utf-8 -*-
# @Time : 2019/3/12 11:46
# @Author : zzt import allure
import pytest @allure.feature('这里是一级标签')
class TestAllure(): @allure.title("用例标题0")
@allure.story("这里是第一个二级标签")
@pytest.mark.parametrize('param', ['青铜', '白银', '黄金'])
def test_0(self, param):
allure.attach('附件内容是: '+param, '我是附件名', allure.attachment_type.TEXT) @allure.title("用例标题1")
@allure.story("这里是第二个二级标签")
def test_1(self):
allure.attach.file(r'E:\Myproject\pytest-allure\test\test_1.jpg', '我是附件截图的名字', attachment_type=allure.attachment_type.JPG) @allure.title("用例标题2")
@allure.story("这里是第三个二级标签")
@allure.severity(allure.severity_level.NORMAL)
def test_2(self):
pass

  执行结果如下:

7.  链接

  @allure.link  @allure.issue  @allure.testcase  

# -*- coding: utf-8 -*-
# @Time : 2019/3/12 11:46
# @Author : zzt import allure
import pytest @allure.feature('这里是一级标签')
class TestAllure(): @allure.title("用例标题0")
@allure.story("这里是第一个二级标签")
@pytest.mark.parametrize('param', ['青铜', '白银', '黄金'])
def test_0(self, param):
allure.attach('附件内容是: '+param, '我是附件名', allure.attachment_type.TEXT) @allure.title("用例标题1")
@allure.story("这里是第二个二级标签")
def test_1(self):
allure.attach.file(r'E:\Myproject\pytest-allure\test\test_1.jpg', '我是附件截图的名字', attachment_type=allure.attachment_type.JPG) @allure.title("用例标题2")
@allure.story("这里是第三个二级标签")
@allure.issue('http://baidu.com', name='点击我跳转百度')
@allure.testcase('http://bug.com/user-login-Lw==.html', name='点击我跳转禅道')
def test_2(self):
pass

  执行结果如下:

  

8 重试

  Allure允许您汇总有关在单次测试运行期间重新执行的测试的信息以及在一段时间内测试执行的历史记录。

  重试需要引入插件:      pip pytest-rerunfailures                      或者手动下载      https://github.com/pytest-dev/pytest-rerunfailures

  

  (未完待续)

  

  

  

    

 

pytest-allure-poco之allure全量详细用法的更多相关文章

  1. Pytest系列(20)- allure结合pytest,allure.step()、allure.attach的详细使用

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 allure除了支持pyte ...

  2. Pytest系列(21)- allure的特性,@allure.description()、@allure.title()的详细使用

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 前面介绍了两种allure的 ...

  3. Pytest系列(23)- allure打标记,@allure.feature()、@allure.story()、@allure.severity()的详细使用

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 前面几篇文章主要介绍了all ...

  4. Pytest系列(22)- allure的特性,@allure.link()、@allure.issue()、@allure.testcase()的详细使用

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 上一篇文章介绍了两种allu ...

  5. pytest(12)-Allure常用特性allure.attach、allure.step、fixture、environment、categories

    上一篇文章pytest Allure生成测试报告我们学习了Allure中的一些特性,接下来继续学习其他常用的特性. allure.attach allure.attach用于在测试报告中添加附件,补充 ...

  6. module 'pytest' has no attribute 'allure'问题解决

    安装allure后执行命令后报错module 'pytest' has no attribute 'allure' C:\Users\Desktop\xin>pytest -s -q --all ...

  7. Pytest自动化测试 - 完美结合Allure

    简介 Allure Framework是一种灵活的.轻量级.多语言测试报告工具. 不仅可以以简洁的网络报告形式非常简洁地显示已测试的内容, 而且还允许参与开发过程的每个人从日常执行中提取最大程度的有用 ...

  8. Pytest(11)allure报告

    前言 allure是一个report框架,支持java的Junit/testng等框架,当然也可以支持python的pytest框架,也可以集成到Jenkins上展示高大上的报告界面. mac环境: ...

  9. pytest文档32-allure描述用例详细讲解

    前言 pytest+allure是最完美的结合了,关于allure的使用,本篇做一个总结. allure报告可以很多详细的信息描述测试用例,包括epic.feature.story.title.iss ...

随机推荐

  1. 箭头函数不会修改this

    function Person () { this.name = 'little bear', this.age = 18 setTimeout(()=>{ console.log(this ) ...

  2. python爬虫入门(二)Opener和Requests

    Handler和Opener Handler处理器和自定义Opener opener是urllib2.OpenerDirector的实例,我们之前一直在使用urlopen,它是一个特殊的opener( ...

  3. HTTP协议简单记录

    http协议的格式 1. 首行 2. 头 3. 空行 4. 体 http请求头 #Referer 请求来自哪里,如果是在http://www.baidu.com上点击链接发出的请求,那么Referer ...

  4. expdb和impdb使用方法

    一  关于expdp和impdp     使用EXPDP和IMPDP时应该注意的事项:EXP和IMP是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用. EXPDP和IMPDP是服务端的工具 ...

  5. mac下的readelf和objdump

    ELF文件包括: (1)可重定位的目标文件 (2)可执行的目标文件 (3)可被共享的目标文件 可以用file命令来看目标文件是否是ELF文件 在linux下,用readelf来看ELF头部或者其它各s ...

  6. Eclipse从数据库逆向生成Hibernate实体类和映射文件(Eclipse插件系列之HibernateTools)

    ♣下载安装Eclipse插件(HibernateTools) ♣Eclipse连接数据库(Mysql5.7) ♣新建hibernate.properties和hibernate.cfg.xml文件 ♣ ...

  7. SSM-Spring-09:Spring中jdk动态代理

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- JDK动态代理: 为何叫JDK动态代理呢? 所谓JDK,jdk是java开发工具包,它里面包含了一个动态代理的 ...

  8. xml序列化和反序列化(二)

    上篇讲到关于xml入参实体序列化,下面给出出参实体反序列化,代码如下: /// <summary> /// 反序列化 /// </summary> /// <param ...

  9. HttpClient 专题

    HttpClient is a HTTP/1.1 compliant HTTP agent implementation based on HttpCore. It also provides reu ...

  10. c# 将一个窗体显示在主窗体中

    Form2 form = new Form2(); //实例化要添加的窗体 form.Show();//显示 form.TopLevel = false; //要将这个顶级窗口设置false pane ...