定制报告需要先导入allure模块,再使用以下装饰器方法:

  • feature: 标注主要功能模块。
  • story: 标注feature功能模块下的分支功能。
  • description:在报告中显示用例描述。
  • step: 标注测试用例步骤。
  • issue && testcase:标注用例关联的链接。
  • attach: 添加一些附加内容到测试报告中。
  • severity: 标注测试用例的重要级别,包含blocker, critical, normal, minor, trivial 几个不同的等级。

feature && story

主要用于为用例分层级

import allure

@allure.feature("评论模块")
class TestComment: @allure.story("填写所有信息,点击提交,预期评论成功")
def test_001(self):
print("\n填写信息")
print("\n点击提交") @allure.story("不输入任何信息,点击提交,预期提示填写必填项")
def test_002(self):
print("\n点击提交")

报告样式如下:

description

用于在报告中增加用例描述信息,除了这个方法外,还可以在方法下使用3个引号的方式增加用例描述信息。

import allure

@allure.feature("评论模块")
class TestComment: @allure.story("填写所有信息,点击提交,预期评论成功")
@allure.description("用例描述...这样...那样...")
def test_001(self):
print("\n填写信息")
print("\n点击提交") @allure.story("不输入任何信息,点击提交,预期提示填写必填项")
def test_002(self):
"""用例描述...也可以...这样...那样"""
print("\n点击提交")

报告样式如下:

step

在报告中增加测试步骤的显示。

import allure

@allure.feature("评论模块")
class TestComment: @allure.story("填写所有信息,点击提交,预期评论成功")
@allure.description("用例描述...这样...那样...")
def test_001(self):
with allure.step("1、填写信息"):
print("\n填写信息")
assert 1 == 1
with allure.step("2、点击提交"):
print("\n点击提交")
assert 2 == 1 @allure.story("不输入任何信息,点击提交,预期提示填写必填项")
def test_002(self):
"""用例描述...也可以...这样...那样"""
print("\n点击提交")

报告样式如下:

issue && testcase

issue与testcase用于在报告中增加关联链接,用法基本一样,第1个参数为关联的url地址,第2个为缺省参数,作用是为地址的别名。

import allure

@allure.feature("评论模块")
class TestComment: @allure.story("填写所有信息,点击提交,预期评论成功")
@allure.description("用例描述...这样...那样...")
@allure.issue("http://www.baidu.com")
@allure.testcase("http://www.baidu.com", "百度一下")
def test_001(self):
with allure.step("1、填写信息"):
print("\n填写信息")
assert 1 == 1
with allure.step("2、点击提交"):
print("\n点击提交")
assert 2 == 1 @allure.story("不输入任何信息,点击提交,预期提示填写必填项")
def test_002(self):
"""用例描述...也可以...这样...那样"""
print("\n点击提交")

报告样式如下:

attach

在报告中添加一些附加内容,内容可以为文本信息、图片、文件等。

import allure

@allure.feature("评论模块")
class TestComment: @allure.story("填写所有信息,点击提交,预期评论成功")
@allure.description("用例描述...这样...那样...")
@allure.issue("http://www.baidu.com")
@allure.testcase("http://www.baidu.com", "百度一下")
def test_001(self):
with allure.step("1、填写信息"):
print("\n填写信息")
assert 1 == 1
with allure.step("2、点击提交"):
print("\n点击提交") # attach 添加文本信息
allure.attach("文本信息标注信息...", "别名")
# attach 可以添加图片
allure.attach.file(r"D:\Users\User\Desktop\图片管理\60-60.jpg", "图片", attachment_type=allure.attachment_type.JPG)
# attach 可以添加html文件
allure.attach.file(r"D:\Users\User\Desktop\图片管理\test.html", "html文件", attachment_type=allure.attachment_type.HTML) @allure.story("不输入任何信息,点击提交,预期提示填写必填项")
def test_002(self):
"""用例描述...也可以...这样...那样"""
print("\n点击提交")

报告样式如下:

severity

为测试用例的划分重要级别,包含blocker, critical, normal, minor, trivial 5个不同的等级。默认是normal级别。

import allure

@allure.feature("评论模块")
class TestComment: @allure.story("填写所有信息,点击提交,预期评论成功")
@allure.description("用例描述...这样...那样...")
@allure.issue("http://www.baidu.com")
@allure.testcase("http://www.baidu.com", "百度一下")
def test_001(self):
with allure.step("1、填写信息"):
print("\n填写信息")
assert 1 == 1
with allure.step("2、点击提交"):
print("\n点击提交") # attach 添加文本信息
allure.attach("文本信息标注信息...", "别名")
# attach 可以添加图片
allure.attach.file(r"D:\Users\User\Desktop\图片管理\60-60.jpg", "图片", attachment_type=allure.attachment_type.JPG)
# attach 可以添加html文件
allure.attach.file(r"D:\Users\User\Desktop\图片管理\test.html", "html文件", attachment_type=allure.attachment_type.HTML) @allure.severity("blocker")
def test_002(self):
pass @allure.severity("critical")
def test_003(self):
pass @allure.severity("minor")
def test_004(self):
assert 1 == 2

报告样式如下:

环境配置信息

在概览中查看环境配置默认是没有的。

若要在报告中增加环境信息需要在第一步生成的json文件中,增加一个environment.properties文件,文件内容如下样式:

systemVersion=win10
pythonVersion=3.8.5
allureVersion=2.13.9
baseUrl=http://192.168.1.x:8080
projectName=test

然后再执行并生成报告,报告样式如下:

在allure 1.X的中,可以通过一个以test开头的py文件来配置,该方法在 2.X已弃用,仅供了解:

报告样式如下:

Pytest_定制allure报告(12)的更多相关文章

  1. allure报告定制(pytest+jenkins)

    环境及安装可查看 pytest+jenkins安装+allure导出报告 要让allure报告更漂亮,更直观,需要在脚本中写入allure特性 一开始allure调用step().story().fe ...

  2. pytest+allure(allure-pytest基于这个插件)设计定制化报告

    一:环境准备 1.python3.6 2.windows环境 3.pycharm 4.allure-pytest 5.allure2.8.0 6.java1.8 allure-pytest快速安装 在 ...

  3. 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 ...

  4. 如何利用jenkins插件查看allure报告-----完整篇(解决404和无数据问题)

    背景: python3+appium+pytest+allure写了安卓的自动化脚本,在windows本机pycharm上跑通过后生成了allure报告.  公司jenkins搭建在linux服务器上 ...

  5. pytest系列(四)- pytest+allure+jenkins - 持续集成平台生成allure报告

    pytest是什么 pytest是python的一款测试框架,拥有unittest的功能并比它更丰富. allure是什么 有非常多的优秀的测试框架,但却是有非常少优秀的报告工具可以展示非常清楚的用例 ...

  6. pytest框架优化——将异常截屏图片加入到allure报告中

    痛点分析: 在做allure定制化的时候,关于附件添加这一块,我们在代码里可以添加我们准备好的附件,这里用图片,通过下面的方法就能实现 allure.attach(file, '图片描述', allu ...

  7. pytest框架之allure报告生成

    一.关于安装 allure是跟pytest一起集成使用的,所以需要同时安装pytest以及allure-pytest插件: pip install pytest pip install allure- ...

  8. pytest生成allure报告

    在pytest框架中可以用很多插件来生成测试报告,本文总结下怎么生成allure报告 allure allure是一款开源的,专门用来展示测试结果的一个工具,allure可以与很多的测试框架做集成,比 ...

  9. 移动自动化appium(2)- Allure报告使用详解

    6 Allure报告 6.1 Allure介绍 Allure是一个独立的报告插件,生成美观易读的报告,比之前的html好看,目前支持的语言:Java.PHP.Ruby.Python.C#等 6.2 A ...

随机推荐

  1. git 使用https方式进行 pull、push代码免密

    由于网络原因我用ssh方法拉取代码每次都提示远程服务连接失败,因此我用了https方式去拉去代码. 这种方式拉取代码每次操作都要输入密码,为了解决这个问题做了一下操作: 在命令行输入 git conf ...

  2. Maven项目打包成war包并启动war包运行

    1 项目打包 1.1 右键点击所需要打包的项目,点击如图所示 Maven clean,这里 Maven 会清除掉之前对这个项目所有的打包信息. 1.2进行完 Maven clean 操作后,在ecli ...

  3. Redis - 2 - 聊聊Redis的RDB和AOF持久化 - 更新完毕

    1.RDB 1.1).RDB是什么? RDB,全称Redis Database RDB是Redis进行持久化的一种方式,当然:Redis默认的持久化方式也是RDB 1.2).Redis配置RDB 1. ...

  4. SharedWorker实现多标签页联动计时器

    web workers对于每个前端开发者并不陌生,在mdn中的定义:Web Worker为Web内容在后台线程中运行脚本提供了一种简单的方法.线程可以执行任务而不干扰用户界面.此外,他们可以使用XML ...

  5. Nginx区分内部与外部

    目录 一.简介 二.配置 一.简介 场景: 当网站需要维护时,访问任何连接都显示维护页面 原理: 将任何访问都重定向到维护页面. 二.配置 server { listen 80; index inde ...

  6. 一文详解 纹理采样与Mipmap纹理——构建山地渲染效果

    在开发一些相对较大的场景时,例如:一片铺满相同草地纹理的丘陵地形,如果不采用一些技术手段,就会出现远处的丘陵较近处的丘陵相比更加的清晰的视觉效果,而这种效果与真实世界中近处的物体清晰远处物体模糊的效果 ...

  7. Android工具 - SQLITE3

    原创文章,如有转载,请注明出处:http://blog.csdn.net/yihui823/article/details/6689922 本文章的前提:已经安装了Eclipse和ADT.androi ...

  8. [BUUCTF]PWN——ez_pz_hackover_2016

    ez_pz_hackover_2016 题目附件 解题步骤: 例行检查,32位,开启了RELRO保护,二进制的保护机制看这里 由于没有开启nx保护,对于这题一开始想到的是利用写入shellcode来获 ...

  9. [BUUCTF]PWN16——jarvisoj_level2

    [BUUCTF]PWN16--jarvisoj_level2 附件 步骤 例行检查,32位,开启了nx保护 试运行一下程序 32位ida载入,shift+f12查看一下程序里的字符串,发现了syste ...

  10. CF1491A K-th Largest Value 题解

    Content 你有一个长度为 \(n\),并且仅包含 \(0/1\) 的数组 \(a\).现在对这个序列做以下两种操作之一共 \(q\) 次: \(1\) \(x\):将 \(a_x\) 修改为 \ ...