Pytest系列(20)- allure结合pytest,allure.step()、allure.attach的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦!
https://www.cnblogs.com/poloyy/category/1690628.html
前言
allure除了支持pytest自带的特性之外(fixture、parametrize、xfail、skip),自己本身也有强大的特性可以在pytest中使用
@allure.step
- allure报告最重要的一点是,它允许对每个测试用例进行非常详细的步骤说明
- 通过 @allure.step() 装饰器,可以让测试用例在allure报告中显示更详细的测试过程
示例代码
#!/usr/bin/env python
# -*- coding: utf-8 -*- """
__title__ =
__Time__ = 2020-04-08 21:24
__Author__ = 小菠萝测试笔记
__Blog__ = https://www.cnblogs.com/poloyy/
"""
import allure @allure.step("第一步")
def passing_step():
pass @allure.step("第二步")
def step_with_nested_steps():
nested_step() @allure.step("第三步")
def nested_step():
nested_step_with_arguments(1, 'abc') @allure.step("第四步{0},{arg2}")
def nested_step_with_arguments(arg1, arg2):
pass @allure.step("第五步")
def test_with_nested_steps():
passing_step()
step_with_nested_steps()
测试用例在allure上的显示
知识点
- step() 只有一个参数,就是title,你传什么,在allure上就显示什么
- 可以像python字符串一样,支持位置参数和关键字参数 {0},{arg2},可看第四步那里,如果函数的参数没有匹配成功就会报错哦
- step() 的使用场景,给我感觉就是,当方法之间嵌套会比较有用,否则的话只会显示一个步骤,类似下面图
allure.attach(挺有用的)
作用:allure报告还支持显示许多不同类型的附件,可以补充测试结果;自己想输出啥就输出啥,挺好的
语法: allure.attach(body, name, attachment_type, extension)
参数列表
- body:要显示的内容(附件)
- name:附件名字
- attachment_type:附件类型,是 allure.attachment_type 里面的其中一种
- extension:附件的扩展名(比较少用)
allure.attachment_type提供了哪些附件类型?
语法二: allure.attach.file(source, name, attachment_type, extension)
source:文件路径,相当于传一个文件
其他参数和上面的一致
其中一个测试用例的代码栗子
#!/usr/bin/env python
# -*- coding: utf-8 -*- """
__title__ =
__Time__ = 2020-04-08 21:24
__Author__ = 小菠萝测试笔记
__Blog__ = https://www.cnblogs.com/poloyy/
"""
import allure
import pytest @pytest.fixture
def attach_file_in_module_scope_fixture_with_finalizer(request):
allure.attach('在fixture前置操作里面添加一个附件txt', 'fixture前置附件', allure.attachment_type.TEXT) def finalizer_module_scope_fixture():
allure.attach('在fixture后置操作里面添加一个附件txt', 'fixture后置附件',
allure.attachment_type.TEXT) request.addfinalizer(finalizer_module_scope_fixture) def test_with_attacments_in_fixture_and_finalizer(attach_file_in_module_scope_fixture_with_finalizer):
pass def test_multiple_attachments():
allure.attach('<head></head><body> 一个HTML页面 </body>', 'Attach with HTML type', allure.attachment_type.HTML)
allure.attach.file('./reports.html', attachment_type=allure.attachment_type.HTML)
运行之后看结果
这是一个txt附件
这是一个用了 allure.attach() 来插入一段自己写的HTML和 allure.attach.file() 来导入一个已存在的HTML文件(pytest-html报告)
Pytest系列(20)- allure结合pytest,allure.step()、allure.attach的详细使用的更多相关文章
- Pytest系列(16)- 分布式测试插件之pytest-xdist的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 平常我们功能测试用例非常多时 ...
- Pytest系列(15)- 多重校验插件之pytest-assume的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 pytest中可以用pyth ...
- Pytest学习(20)- allure之@allure.step()、allure.attach的详细使用
一.@allure.step的用法 可以理解为我们编写测试用例中的每一步操作步骤,而在allure中表示对每个测试用例进行非常详细的步骤说明 通过 @allure.step(),可以让测试用例在all ...
- Pytest系列(21)- allure的特性,@allure.description()、@allure.title()的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 前面介绍了两种allure的 ...
- Pytest 系列(27)- allure 命令行参数
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 先看看 allure 命令的帮助文 ...
- Pytest 系列(24)- allure 环境准备
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html allure 和 pytest 相 ...
- Pytest 系列(28)- 参数化 parametrize + @allure.title() 动态生成标题
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 参数化 @pytest.ma ...
- Pytest 系列(29)- 详解 allure.dynamic 动态生成功能
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 @allure.title ...
- pytest系列(四)- pytest+allure+jenkins - 持续集成平台生成allure报告
pytest是什么 pytest是python的一款测试框架,拥有unittest的功能并比它更丰富. allure是什么 有非常多的优秀的测试框架,但却是有非常少优秀的报告工具可以展示非常清楚的用例 ...
随机推荐
- MybatisPlus SQL 打印控制台
#applicaton.yml 配置 mybatis-plus: configuration: # 是否将sql打印到控制面板(该配置会将sql语句和查询的结果都打印到控制台) log-impl: o ...
- 114 Flatten Binary Tree to Linked List [Python]
114 Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place. 将二 ...
- C语言学生管理系统
想练习一下链表,所以就有了这个用C写的学生管理系统 没有把它写入文件,才不是因为我懒哈哈哈,主要是为了练习链表的 #include<stdio.h> #include<stdlib. ...
- Python第五章-内置数据结构05-集合
Python内置数据结构 五.集合(set) python 还提供了另外一种数据类型:set. set用于包含一组无序的不重复对象.所以set中的元素有点像dict的key.这是set与 list的最 ...
- mysql事务提交和回滚机制
应用场景: 银行取钱,从ATM机取钱,分为以下几个步骤 1 登陆ATM机,输入密码: 2 连接数据库,验证密码: 3 验证成功,获得用户信息,比如存款余额等: 4 用 ...
- w3cshool -- 排列组合去重算法挑战
function permAlone(str) { if(str.length == 1) return str; var a = str.substr(0, 1), one = [a], count ...
- POJ - 1276 二进制优化多重背包为01背包
题意:直接说数据,735是目标值,然后3是后面有三种钱币,四张125的,六张五块的和三张350的. 思路:能够轻易的看出这是一个多重背包问题,735是背包的容量,那些钱币是物品,而且有一定的数量,是多 ...
- PHP一致性hash
PHP提供了两种比较两个变量的方法: 松散比较使用 == or != : 两个变量都具有“相同的值”. 严格比较 === or !== : 两个变量都具有“相同的类型和相同的值”. 类型杂耍 真实陈述 ...
- coding++:对List中每个对象元素按时间顺序排序
需求: 需要对List中的每个User按照birthday顺序排序,时间由小到大排列. package com.tree.ztree_demo.orderby; import java.text.Si ...
- [vijos1574]摇钱树<dp+贪心>
题目链接:https://vijos.org/p/1574 这道题是昨晚一个叫Ztravellers的大佬推荐的,确实觉得这是一道很有意思的题,很多方面都很有意思: 初见这道题,估计想法都是贪心,因为 ...