前言

pytest 结合 allure 描述用例的时候我们一般使用 @allure.title@allure.description 描述测试用例的标题和详情。

在用例里面也可以动态更新标题和详情,使用allure.dynamic方法实现。

allure.dynamic 动态属性

feature 模块

allure.dynamic.feature(feature_name)

功能点 story

allure.dynamic.story(case_story)

用例标题 title

allure.dynamic.title(case_title)

用例描述:请求URL 请求类型 期望结果 实际结果描述

desc = "<font color='red'>请求URL:</font>{}<Br/>" \
"<font color='red'>请求类型:</font>{}<Br/>" \
"<font color='red'>期望结果:</font>{}<Br/>" \
"<font color='red'>实际结果描述:</font>{}<Br/>".format(url,method,expect,expect_result)
allure.dynamic.description(desc)

description 用例描述

可以在测试主体内部动态更新描述 allure.dynamic.description

import allure

@allure.description("""
This description will be replaced at the end of the test.
""")
def test_dynamic_description():
assert 42 == int(6 * 7)
allure.dynamic.description('A final description.')

最后用例的描述被更新为 'A final description.'

title 用例标题

用例标题也可以被动态更新

@allure.title("This title will be replaced in a test body")
def test_with_dynamic_title():
assert 2 + 2 == 4
allure.dynamic.title('After a successful test finish, the title was replaced with this line.')

最终用例的title更新为'After a successful test finish, the title was replaced with this line.'

参数化

参数化时候,可以使用@allure.title给用例不同标题

@allure.title("Parameterized test title: adding {param1} with {param2}")
@pytest.mark.parametrize('param1,param2,expected', [
(2, 2, 4),
(1, 2, 5)
])
def test_with_parameterized_title(param1, param2, expected):
assert param1 + param2 == expected

也可以在用例里面使用allure.dynamic.title更新用例的标题

import pytest
import allure
# 作者:上海-悠悠 QQ交流群:779429633 def login(username, password):
'''登录'''
print("输入账号:%s" % username)
print("输入密码:%s" % password)
# 返回
return {"code": 0, "msg": "success!"} # 测试数据
test_datas = [
({"username": "yoyo1", "password": "123456"}, "success!", "输入正确账号,密码,登录成功"),
({"username": "yoyo2", "password": "123456"}, "failed!", "输入错误账号,密码,登录失败"),
({"username": "yoyo3", "password": "123456"}, "success!", "输入正确账号,密码,登录成功"),
] @allure.story("登录用例")
@pytest.mark.parametrize("test_input,expected,title",
test_datas
)
def test_login(test_input, expected, title):
'''测试登录用例'''
# 获取函数返回结果
result = login(test_input["username"], test_input["password"])
# 断言
assert result["msg"] == expected
allure.dynamic.title(title)

最终生成报告效果

pytest文档44-allure.dynamic动态生成用例标题的更多相关文章

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

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

  2. pytest文档3-pytest+Allure+jenkins+邮箱发送

    前言: 虽然网上有很多邮件配置的文章,但还是想自己写一下配置的过程,因为在中间也碰到了不同坑.按照这个文档配置的话,99%都可以成功.   一.jenkins 配置邮箱 1.打开jenkins后进入点 ...

  3. pytest文档2-pytest+Allure+jenkins+邮箱发送

    前言: 上一章节讲解了tomcat+jenkins的环境搭建,这一章节主要讲一下Allure报告在jenkins上的配置 步骤: 1.新建一个item 2.输入项目的名称,选择自由风格,点击保存 3. ...

  4. pytest文档1-pytest+Allure+jenkins+邮箱发送

    前言: 1.pytest+allure是目前很多公司使用较多的一种报告样式,因为它更详细,各种指标更直观(简单的说就是看着更高大上,更能装X). 环境准备: 1.Windows10 2.Allure ...

  5. pytest文档7-pytest-html生成html报告

    前言 pytest-HTML是一个插件,pytest用于生成测试结果的HTML报告.兼容Python 2.7,3.6 pytest-html 1.github上源码地址[https://github. ...

  6. pytest文档3-pycharm运行pytest

    前言 上一篇pytest文档2-用例运行规则已经介绍了如何在cmd执行pytest用例,平常我们写代码在pycharm比较多 写完用例之后,需要调试看看,是不是能正常运行,如果每次跑去cmd执行,太麻 ...

  7. 解决SharePoint文档库文件在搜索结果页面显示的标题和文档的标题不一致问题(search result)

    问题表现: SharePoint 2013 爬网后,搜索一个文档,虽然搜到了,但是显示有点问题,如图: 原因分析: 造成该问题的原因是,该文档除了本身有一个名称外,在文档metadata的title属 ...

  8. pytest文档8-参数化(parametrize)结合allure.title()生成不同标题报告

    参数化parametrize 先看一个简单的pytest参数化案例演示test_a.py # test_a.py import pytest import allure def login(usern ...

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

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

随机推荐

  1. ubuntu18.04 docker安装mongo

    问题 在docker中安装的mongo连接不上,报错信息 feng@ubuntu:/etc/docker$ mongo MongoDB shell version v3.6.3 connecting ...

  2. leetcode刷题-79单词搜索

    题目 给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格.同一个单元格内的字母不允许被重复 ...

  3. Mybatis动态SQL配置

    使用 if where foreach标签对映射配置文件中sql语句进行动态配置 1.首先在dao接口中设置两个查询方法 package sun.dao; import sun.domain.Quer ...

  4. 超详细!盘点Python中字符串的常用操作

    在Python中字符串的表达方式有四种 一对单引号 一对双引号 一对三个单引号 一对三个双引号 a = 'abc' b= "abc" c = '''abc''' d = " ...

  5. zepto | 用事件委托去解决无法给新增添的DOM添加事件的问题

    前段时间在做一个任务的时候,碰见了一个问题:zepto无法用on事件去监听新增加的dom事件.这个问题用live可解决, 但是live在ios下失效,为了解决这个问题,我采用了暴力的方法去解决,每次添 ...

  6. Windows Server系统部署MySQL数据库

    由于工作需要在阿里云服务器中使用MySQL,所以安装一下MySQL数据库,中间也踩了一些坑,现在将整个过程给大家记录下来,便于后续查找. 阿里云服务器是WinServer2012系统,之前在Windo ...

  7. ribbon源码(3) 配置模块

    ribbon的很多功能可以通过配置进行调整,ribbon通过IClientConfig来获取配置信息,用户可以通过实现IClientConfig来管理配置. ribbon也提供了默认的实现(Defau ...

  8. 为什么我选择MySQL Workbench・一

    一.官方 官方提供的工具必然有其优势. MySQL Workbench有两个版本,社区版和商业版.社区版是免费的. 二.第一个选择 使用MySQL之前用的是SQL Server而微软的东西一般都使用微 ...

  9. breakpad系列(2)——在Linux中使用breakpad

    本文来自breakpad源码目录中doc目录下的linux_starter_guide.md,建议直接去看原文. 如何将breakpad添加进你的Linux程序 本文档是在Linux上使用Breakp ...

  10. Java Web学习(六)HttpServletRequest(客户端请求)

    一.定义 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象提供的方法,可以获得客户端请求的所有 ...