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
相关推荐
鹿鸣悠悠1 天前
pytest + requests + allure 接口自动化测试框架指南
pytest
忘忧记2 天前
pytest进阶参数化用法
前端·python·pytest
bug_rabbit2 天前
pytest-html 中文乱码问题终极解决方案(Windows版)
windows·html·pytest
庄小法2 天前
pytest
开发语言·python·pytest
工具人55552 天前
pytest练习
pytest
好家伙VCC3 天前
# Pytest发散创新:从基础测试到智能断言的实战进阶指南在现代软
java·python·pytest
小罗和阿泽3 天前
GUI 自动化测试 pywinauto测试框架
开发语言·python·功能测试·测试工具·pytest
文人sec4 天前
抛弃 Postman!用 Pytest+Requests+Allure+Playwright+Minium 搭建高逼格接口+UI自动化测试平台
自动化测试·python·测试工具·ui·pytest·playwright
曲幽4 天前
FastAPI单元测试实战:别等上线被喷才后悔,TestClient用对了真香!
python·单元测试·pytest·api·fastapi·web·httpx·testclient·依赖项覆盖
小罗和阿泽4 天前
接口测试系列 接口自动化测试 pytest框架(四)
pytest