Pytest系列(21)- allure的特性,@allure.description()、@allure.title()的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦!
https://www.cnblogs.com/poloyy/category/1690628.html
前言
上一篇文章介绍了两种allure的特性
- @allure.step() 装饰器:可以设置测试步骤,让测试用例的执行过程更加详细
- allure.attach() 函数:可以设置需要显示在allure报告的附件,包含了多种类型,可以通过allure.attachment_type查看支持的类型
这一篇幅,我们主要来讲解另外两个特性,可以增加报告的可读性哦!
- @allure.description()
- @allure.title()
它们用法极其相近,只是作用不一样而已
@allure.description()
作用
可以添加足够详细的测试用例描述,以便于管理层查看哦哈哈哈
语法格式,有三种
- @allure.description(str)
- 在测试用例函数声明下方添加""" """
- @allure.description_html(str):相当于传一个HTML代码组成的字符串,类似allure.attach()中传HTML
注意:方式一方式二的效果和作用是一致的, 哪个方便哪个来
#!/usr/bin/env python
# -*- coding: utf-8 -*- """
__title__ =
__Time__ = 2020-04-18 15:24
__Author__ = 小菠萝测试笔记
__Blog__ = https://www.cnblogs.com/poloyy/
""" import allure import allure # 方式一
@allure.description("""
这是一个@allure.description装饰器
没有特别的用处
""")
def test_description_from_decorator():
assert 42 == int(6 * 7) # 方式二
def test_unicode_in_docstring_description():
"""
当然,在方法声明的下一行这样子写,也算一种添加description的方式哦
"""
assert 42 == int(6 * 7) # 方式三
@allure.description_html("""
<h1>Test with some complicated html description</h1>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr align="center">
<td>William</td>
<td>Smith</td>
</table>
""")
def test_html_description():
assert True
运行结果
方式一的allure报告
方式二的allure报告
方式三的allure报告
@allure.title()
作用
- 使得测试用例的标题更具有可读性,毕竟我们可以写成中文
- 支持占位符传递关键字参数哦
具体栗子一
#!/usr/bin/env python
# -*- coding: utf-8 -*- """
__title__ =
__Time__ = 2020-04-18 16:09
__Author__ = 小菠萝测试笔记
__Blog__ = https://www.cnblogs.com/poloyy/
""" import pytest, allure @allure.title("前置操作:登录")
@pytest.fixture
def test_loginss(request):
params = request.param
name = params["username"]
pwd = params["pwd"]
allure.attach(f"这是测试用例传的参数{params}")
print(name, pwd, params)
yield name, pwd @allure.title("成功登录,测试数据是:{test_loginss}")
@pytest.mark.parametrize("test_loginss", [
{"username": "name1", "pwd": "pwd1"},
{"username": "name2", "pwd": "pwd2"}], indirect=True)
def test_success_login(test_loginss):
name, pwd = test_loginss
allure.attach(f"账号{name},密码{pwd}")
运行结果,查看allure报告
这是一次综合多个之前学到的方法来完成的栗子,已经具体标出来啦!
具体栗子二
@allure.title("多个参数{name},{phone},{age}")
@pytest.mark.parametrize("name,phone,age", [
(1, 2, 3),
(4, 5, 6),
(7, 8, 9)
])
def test_test_test(name, phone, age):
print(name, phone, age)
运行结果,查看allure报告
总结
如果没有添加 @allure.title() 的话,测试用例的标题默认就是函数名,这样的可读性不高,毕竟咱们是中国人,显示中文title还是很有必要的~所以墙裂建议大伙儿加上啦!
Pytest系列(21)- allure的特性,@allure.description()、@allure.title()的详细使用的更多相关文章
- 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系列(22)- allure的特性,@allure.link()、@allure.issue()、@allure.testcase()的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 上一篇文章介绍了两种allu ...
- Pytest系列(20)- allure结合pytest,allure.step()、allure.attach的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 allure除了支持pyte ...
- Pytest系列(23)- allure打标记,@allure.feature()、@allure.story()、@allure.severity()的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 前面几篇文章主要介绍了all ...
- Pytest 系列(29)- 详解 allure.dynamic 动态生成功能
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 @allure.title ...
- Pytest 系列(27)- allure 命令行参数
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 先看看 allure 命令的帮助文 ...
- Pytest 系列(28)- 参数化 parametrize + @allure.title() 动态生成标题
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 参数化 @pytest.ma ...
- pytest(12)-Allure常用特性allure.attach、allure.step、fixture、environment、categories
上一篇文章pytest Allure生成测试报告我们学习了Allure中的一些特性,接下来继续学习其他常用的特性. allure.attach allure.attach用于在测试报告中添加附件,补充 ...
随机推荐
- Deep Protein Methylation Profiling by Combined Chemical and Immunoaffinity Approaches Reveals Novel PRMT1 Targets (结合层析法和免疫沉淀法的蛋白甲基化的深度检测技术发现了PRMT1新的靶标蛋白)
题目:Deep Protein Methylation Profiling by Combined Chemical and Immunoaffinity Approaches Reveals Nov ...
- vue 3
目录 复习 Vue项目需要自建服务器:node npm:包管理器 - 为node拓展功能的 vue cli环境:脚手架 - 命令行快速创建项目 创建Vue项目 启动项目 项目目录 组件 在根组件中渲染 ...
- python浅学【网络服务中间件】之RabbitMQ
一.关于AMQP: AMQP,即Advanced Message Queuing Protocol,高级消息队列协议. AMQP使符合要求的客户端应用程序能够与符合要求的消息传递中间件代理进行通信. ...
- bzoj4693
题意 bzoj 做法 结论1:对于\((X_1,X_2,...,X_k)\),其为红的充要条件为:令\(Y_i=X_i-1\),\(\prod\limits_{k=1}^K {\sum\limits_ ...
- linux-aapt文件调用问题
使用管理后台上传移动app安装包到服务器,出现异常问题,解决方案如下: 本地环境说明: 系统:linux(centos 64位) 远程工具:xshell 数据库:oracle 中间件:weblogic ...
- swagger2 接口文档,整个微服务接口文档
1,因为整个微服务会有好多服务,比如会员服务,支付服务,订单服务,每个服务都集成了swagger 我们在访问的时候,不可能每个服务输入一个url 去访问,看起来很麻烦,所以我们需要在一个页面上集成整个 ...
- A song for a new begining 8月26日到10月11日 第一阶段
- 谈谈flex布局实现水平垂直居中
我们在这要谈的是用flex布局来实现水平和垂直居中.随着移动互联网的发展,对于网页布局来说要求越来越高,而传统的布局方案对于实现特殊布局非常不方便,比如垂直居中.所以09年,W3C 提出了一种新的方案 ...
- 死磕Lambda表达式(六):Consumer、Predicate、Function复合
你的无畏来源于无知.--<三体> 在上一篇文章(传送门)中介绍了Comparator复合,这次我们来介绍一下其他的复合Lambda表达式. Consumer复合 Consumer接口中,有 ...
- prometheus+grafana实现监控过程的整体流程
prometheus安装较为简单,下面会省略安装步骤: 一.服务器启动 Prometheus启动 ./prometheus --config.file=prometheus.yml Grafana启动 ...