前言

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. leetcode刷题-88.合并两个有序数组

    题目 给你两个有序整数数组 nums1 和 nums2,请你将 nums2 合并到 nums1 中,使 nums1 成为一个有序数组. 说明: 初始化 nums1 和 nums2 的元素数量分别为 m ...

  2. leetcode刷题-77组合

    题目 给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合. 示例: 输入: n = 4, k = 2输出:[ [2,4], [3,4], [2,3], [1,2], [1,3 ...

  3. 使用fiddler和安卓模拟器抓取安卓客户端数据包

    安卓模拟器要选可以桥接网络的,本文中用的是雷电模拟器. 软件的安装都很简单,在此不再赘述. fiddler中的设置 首先,打开fiddler,点击Tools选项卡下的Options. 切换到https ...

  4. oracle之WHERE子句中常用的运算符

    WHERE子句中常用的运算符 4.1 运算符及优先级: 算数运算符*,/,+,-, 逻辑运算符not, and ,or 比较运算符 单行比较运算 =,>, >=,<,<=, & ...

  5. oracle之dblink

    当用户要跨本地Oracle数据库,访问另外一个数据库表中的数据时,本地数据库中必须创建了远程数据库的dblink,通过dblink本地数据库可以像访问本地数据库一样访问远程数据库表中的数据.下面讲介绍 ...

  6. PhpStorm license server(版权许可服务器)在线激活服务器集群列表

    原文链接:https://bingyishow.top/easy/55.html 服务器列表 序号 服务器(域名) 状态 1 http://www.yuanzhaoyi.cn 在线 2 http:// ...

  7. [LeetCode]1114. 按序打印(并发)

    ####题目 我们提供了一个类: public class Foo {   public void one() { print("one"); }   public void tw ...

  8. StringBuilder 比 String 快?空嘴白牙的,证据呢!

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 聊的是八股的文,干的是搬砖的活! 面我的题开发都用不到,你为什么要问?可能这是大部分 ...

  9. RXJAVA之概述

    RXjava是一个异步和基于事件的程序库.RXjava的核心理念是编程风格的的变化,从传统的命令式程序改变到函数响应式编程. RXjava的基本概念: Observable:发射源,即对象产生的地方. ...

  10. Druid实现数据库连接用户密码加密

    使用ConfigFilter ConfigFilter的作用包括: 从配置文件中读取配置 从远程http文件中读取配置 为数据库密码提供加密功能 1 配置ConfigFilter 1.1 配置文件从本 ...