如果你还想从头学起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. Hive 时间操作

    Hive 时间转换 UNIX时间戳概念:因为UNIX时间戳只是一个秒数,一个UNIX时间戳在不同时区看来,时间是不同的.如UNIX时间戳0,在0时区看来是1970-01-01 00:00:00,在东八 ...

  2. Python-生成器实现简单的"生产者消费者"模型

    一.使用生成器实现简单的生产者消费者模型, 1.效果截屏 代码如下: import time def consumer(name): print('%s 开始买手机' %name) while Tru ...

  3. [剑指offer]10.斐波那契数列+青蛙跳台阶问题

    10- I. 斐波那契数列 方法一 Top-down 用递归实现 def fibonacci(n): if n <= 0: return 0 if n == 1: return 1 return ...

  4. IdentityServer4源码解析_1_项目结构

    目录 IdentityServer4源码解析_1_项目结构 IdentityServer4源码解析_2_元数据接口 IdentityServer4源码解析_3_认证接口 IdentityServer4 ...

  5. 牛客网剑指offer【Python实现】——part2

    不用加减乘除做加法 写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号. 两个数异或:相当于每一位相加,而不考虑进位: 两个数相与,并左移一位:相当于求得进位: 将上述两步的 ...

  6. 为什么你的程序配了classpath还是找不到类

    classpath简介 classpath是java程序时拥有的一个系统变量,这个变量可以通过如下方式获取 System.out.println(System.getProperty("ja ...

  7. 微服务实战——高可用的SpringCloudConfig

    管理微服务配置 对于单体应用架构来说,会使用配置文件管理我们的配置,这就是之前项目中的application.properties或application.yml.如果需要在多环境下使用,传统的做法是 ...

  8. Mysql中的三类锁,你知道吗?

    导读 正所谓有人(锁)的地方就有江湖(事务),人在江湖飘,怎能一无所知? 今天来细说一下Mysql中的三类锁,分别是全局锁.表级锁.行级锁. 文章首发于作者公众号[码猿技术专栏],原创不易,喜欢的点个 ...

  9. 【深度学习】perceptron(感知机)

    目录 1.感知机的描述 2.感知机解决简单逻辑电路,与门的问题. 2.多层感应机,解决异或门 个人学习笔记,有兴趣的朋友可参考. 1.感知机的描述 感知机(perceptron)由美国学者Frank ...

  10. FaceBook 发布星际争霸最大 AI 数据集

    简介 我们刚发布了最大的星际争霸:Brood War 重播数据集,有 65646 个游戏.完整的数据集经过压缩之后有 365 GB,1535 million 帧,和 496 million 操作动作. ...