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

相关推荐
手揽回忆怎么睡5 分钟前
Streamlit学习笔记
笔记·学习
yongche_shi11 分钟前
第八十八篇: 设计一个配置中心
python·面试宝典·设计一个配置中心
itwangyang52030 分钟前
AIDD药物筛选与设计详细方法
人工智能·python
悟能不能悟37 分钟前
JAVA 对象转为二级制流,再转化为base64
java·开发语言
NiceAsiv42 分钟前
VSCode之打开python终端 取消conda activate的powershell弹窗
vscode·python·conda
潲爺44 分钟前
Java-IO笔记
java·笔记·学习
蔚说1 小时前
is 与 == 的区别 python
python
cnxy1881 小时前
围棋对弈Python程序开发完整指南:步骤3 - 气(Liberties)的计算算法设计
python·算法·深度优先
进击的前栈1 小时前
Flutter跨平台网络图片缓存库cached_network_image鸿蒙化适配指导手册
开发语言·网络·rust
叶子2024221 小时前
骨架点排序计算
python