从0开始python学习-38.pytest的parametrize结合yaml实现数据驱动

目录

[1. 数据驱动](#1. 数据驱动)

[2. 定制化allure报告](#2. 定制化allure报告)


1. 数据驱动

yaml文件中写入

python 复制代码
-
  data: 1
  ces: 2

- test:
  data: 3

数据驱动:@pytest.mark.parametrize("参数名","参数值(可以是list或tuple)")

注意:这里参数值只能是列表或者元组,由于yaml的特性,最好写成列表,如果写成了字典则无法读取

python 复制代码
@pytest.mark.parametrize("caseinfo",YamlUtil("./common/test_api.yaml").read_yaml())
def test_b(self,caseinfo):
    print(caseinfo)
    print(caseinfo["data"])

打印结果:

注意:这里有多个case的情况,每个case下的key值最好一致

2. 定制化allure报告

python 复制代码
-
  title: 用例1

- test:
  title: 用例2

定制化title,定制其他的同理即可

python 复制代码
@allure.epic('测试报告')
@allure.feature('测试模块')
@pytest.mark.parametrize("caseinfo",YamlUtil("./common/test_api.yaml").read_yaml())
def test_b(self,caseinfo):
    allure.dynamic.title(caseinfo["title"])
    print(caseinfo["data"])

allure报告:

相关推荐
TonyLee0179 分钟前
使用argparse模块以及shell脚本
python
Blossom.11829 分钟前
Prompt工程与思维链优化实战:从零构建动态Few-Shot与CoT推理引擎
人工智能·分布式·python·智能手机·django·prompt·边缘计算
云栖梦泽39 分钟前
鸿蒙应用AI赋能与国际化落地实战:让待办应用跨越语言与智能边界
开发语言·鸿蒙系统
CoderCodingNo1 小时前
【GESP】C++五级真题(结构体排序考点) luogu-B3968 [GESP202403 五级] 成绩排序
开发语言·c++·算法
想做后端的小C1 小时前
Java:接口回调
java·开发语言·接口回调
love530love2 小时前
Windows 11 下 Z-Image-Turbo 完整部署与 Flash Attention 2.8.3 本地编译复盘
人工智能·windows·python·aigc·flash-attn·z-image·cuda加速
麒qiqi2 小时前
理解 Linux IO 多路复用
开发语言·数据库
MediaTea3 小时前
Python:模块 __dict__ 详解
开发语言·前端·数据库·python
jarreyer3 小时前
python,numpy,pandas和matplotlib版本对应关系
python·numpy·pandas
代码or搬砖3 小时前
HashMap源码
开发语言·python·哈希算法