前言

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. 基础Html重点——防健忘

    一.head标签重点 <head> <meta charset="utf-8"> <title>第二天课</title> <! ...

  2. 手把手带你体验鸿蒙 harmonyOS

    wNlRGd.png 前言 本文已经收录到我的 Github 个人博客,欢迎大佬们光临寒舍: 我的 GIthub 博客 学习导图 image.png 一.为什么要尝鲜 harmonyos? wNlfx ...

  3. C++ Templates (2.3 类模板的局部使用 Partial Usage of Class Templates)

    返回完整目录 目录 2.3 类模板的局部使用 Partial Usage of Class Templates 2.3.1 Concepts 2.3 类模板的局部使用 Partial Usage of ...

  4. [CF571B]Minimization(贪心+DP)

    题目链接 http://codeforces.com/problemset/problem/571/B 题意 给数组,得到公式最小值. 题解 由题分成的子数组只有两种长度,每种长度的数组数量也是固定的 ...

  5. python里面的project、package、module分别是什么

    2020/5/25 1.project(项目) project 即项目,是一个很大的文件夹,里面有好多的 .py 文件. 在Spyder 中点击菜单栏 projects ----->  new ...

  6. Spring中同一个service中方法相互调用事务不生效问题解决方案

    问题描述: 我们在用Spring框架开发Web项目过程中,经常需要用同一个service中的一个方法调用另一个方法,如果此时调用方没有添加事务注解@Transactional,而在被调用方添加事务注解 ...

  7. vue中配置axios.js文件,发送请求

    为了统一管理请求,每个项目都会去配置axios:而不是在vue中直接使用,那样不好维护等等 下面是我配置的最基础的axios文件 第一步:首先新建一个axios文件,我是放在router文件下的 im ...

  8. Powershell编程基础-002-日期及日期格式化

    在Powershell中,关于日期,时间计算与格式化,常用的如下: $today=Get-Date                                                    ...

  9. dubbo学习(四)配置dubbo 注解方式配置

    provider(生产者) service注解暴露服务 /** * 用户管理实现类 */ @Service //用的dubbo的注解,表明这是一个分布式服务 @Component //注册为sprin ...

  10. shiro-重写标签功能----shiro:hasPermission 标签重写

    public abstract class ShiroAuthorizingRealm extends AuthorizingRealm{ private static final String OR ...