从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报告:

相关推荐
卷无止境14 分钟前
Python能做嵌入式开发吗?一份写给动手派的生态与硬件全景图
后端·python
月光船幽幽4 小时前
检测用户意图复杂性的关键方法
人工智能·python
OPEN-F5 小时前
C++进阶教程:继承与多态
开发语言·c++
Bruce_Liuxiaowei7 小时前
从基础理论开始学习人工智能(三):盲目搜索——从状态空间图到生成-测试范式
人工智能·学习
luj_17687 小时前
大律师考核应重能力与科技素养
c语言·开发语言·c++·经验分享·算法
有梦想的骇客7 小时前
PyTorch学习笔记
pytorch·笔记·学习
威联通网络存储7 小时前
TS-h3087XU-RP 汽车零部件质检追溯部署
python·汽车
你驴我7 小时前
WhatsApp 多账号场景下的会话归档与历史消息检索优化实践
后端·python
IT毕设实战小研7 小时前
基于安卓的空气质量查询系统
android·大数据·vue.js·爬虫·python·django·课程设计
陈年老古董8 小时前
深度学习入门笔记:从神经元到深度神经网络
人工智能·笔记·深度学习·神经网络·学习