Pytest之parametrize()实现数据驱动

一、Pytest之parametrize()实现数据驱动

方法:

@pytest.mark-parametrize(argsname,args_value)

args_name:参数名称,用于将参数值传递给函数

args value:参数值:(列表和字典列表,元组和字典元组),有n个值那么用例执行n次

第一种用法:

python 复制代码
@pytest.mark.parametrize("caseinfo",["百里","星摇","依然"])
def test el get token(self,caseinfo):
    print("获取统一接口鉴权码:"+caseinfo)

第二种用法:

python 复制代码
@pytest.mark.parametrize( 'arg1,arg2",[['name,"百里"],['age"2 def test 01 get token(self,arg1,arg2):
print("获取统一接口鉴权码:"+str(arg1)+""+str(arg2))

二、YAML格式测试用例读,写,封装

1、yaml是一种数据格式,扩展名可以是yaml,yml,支持#注释,通过缩进标识层级,区分大小写

用途:

用于做配置文件(yaml,ini)

用于编写自动化测试用例

2、数据组成

python 复制代码
a、map对象:键:(空格)值
name: 阿里



b、数组(list)使用"-"表示
name:
  - name1: 百度
  - name2: 阿里
  - age:
    - age1: 19
    - age2: 20
相关推荐
昔我往昔2 天前
pytest日志问题排查记录
python·pytest
黄昏恋慕黎明5 天前
博客论坛技术迭代
python·pytest
2601_962078235 天前
Python接口自动化流程(pytest)
python·pytest·接口自动化·测试框架·断言
杨女士YRJ5 天前
python+pytest+01
python·pytest
2601_962078236 天前
Python接口自动化框架:pytest
python·pytest·接口自动化·测试框架·restfulapi
2601_962078196 天前
Appium+Python+pytest自动化测试框架详解
自动化测试·python·appium·pytest·移动应用
2601_962284508 天前
安卓APP UI自动化测试:Python + UiAutomator2 + pytest + pytest-html
python·pytest·uiautomator2·ui自动化测试·安卓app
2601_962300818 天前
基于pytest的接口自动化测试:使用requests模块的实战项目与接口关联方法详解
接口自动化测试·测试用例·pytest·接口关联·requests模块
2601_962300818 天前
Python + Requests + Pytest + Excel + Allure:接口自动化测试项目实战
python·excel·pytest·allure·requests
11路没有终点9 天前
Pytest 安装、版本与第一个测试用例
测试用例·pytest