如果你还想从头学起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()的详细使用的更多相关文章

  1. Pytest系列(16)- 分布式测试插件之pytest-xdist的详细使用

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 平常我们功能测试用例非常多时 ...

  2. Pytest系列(15)- 多重校验插件之pytest-assume的详细使用

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 pytest中可以用pyth ...

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

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

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

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

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

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

  6. Pytest 系列(29)- 详解 allure.dynamic 动态生成功能

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

  7. Pytest 系列(27)- allure 命令行参数

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 先看看 allure 命令的帮助文 ...

  8. Pytest 系列(28)- 参数化 parametrize + @allure.title() 动态生成标题

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 参数化 @pytest.ma ...

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

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

随机推荐

  1. 从原子类和Unsafe来理解Java内存模型,AtomicInteger的incrementAndGet方法源码介绍,valueOffset偏移量的理解

    众所周知,i++分为三步: 1. 读取i的值 2. 计算i+1 3. 将计算出i+1赋给i 可以使用锁来保持操作的原子性和变量可见性,用volatile保持值的可见性和操作顺序性: 从一个小例子引发的 ...

  2. ADO.NET 的使用(一)

    一.ADO.NET概要 ADO.NET 是一组向 .NET Framework 程序员公开数据访问服务的类. ADO.NET 为创建分布式数据共享应用程序提供了一组丰富的组件. 它提供了对关系数据.X ...

  3. Spring bean配置 入门

    Spring 的入门案例:(IOC)  IOC 的底层实现原理(结构图2.01) 图:2.01 IOC:Inversion of Control 控制反转,指的是对象的创建权反转(交给)给Spring ...

  4. List集合概述和特点

    List集合概述 有序集合(也称序列)用户可以精确控制列表的每一个元素的位置插入,用户可以通过整数索引访问元素,并搜索列表中的元素 与set集合不同,列表通常允许重复的元素 List集合的特点 有序: ...

  5. Selenium系列(六) - 强制等待、隐式等待、显式等待

    如果你还想从头学起Selenium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1680176.html 其次,如果你不懂前端基础知识, ...

  6. 【2020-03-28】Dubbo源码杂谈

    前言 本周空闲时间利用了百分之六七十的样子.主要将Dubbo官网文档和本地代码debug结合起来学习,基本看完了服务导出.服务引入以及服务调用的过程,暂未涉及路由.字典等功能.下面对这一周的收获进行一 ...

  7. shell脚本的函数介绍和使用案例

    #前言:今天我们来聊聊shell脚本中的函数知识,看一下函数的优势,执行过程和相关的使用案例,我们也来看一下shell和python的函数书写方式有什么不同 #简介 .函数也具有别名类似的功能 .函数 ...

  8. Node/Python 工具搭建cmder和nrm

    一.安装cmder cmder是windows下的一款终端工具,支持很多linux命令,用起来还是很爽的. 1.安装 http://cmder.net/ 直接在官网下载,解压即可. 2.cmder配置 ...

  9. 拒绝了对对象 '***' (数据库 'BestSoftDB_P',架构 'sale')的 EXECUTE 权限。

    问题描述: 给普通用户授予读写权限,之后研发反映查询语句报错: nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: ...

  10. iOS URL schemes

    来源:知乎 launch center pro支持的参数主要有两个,[prompt]文本输入框和[clipboard]剪贴板 淘宝宝贝搜索 taobao://http://s.taobao.com/? ...