D105【python 接口自动化学习】- pytest进阶参数化用法

day105 pytest参数化parametrize多参数

学习日期:20241224

学习目标:pytest基础用法 -- pytest参数化parametrize多参数

学习笔记:

参数化 parametrize
python 复制代码
# 多次循环
@pytest.mark.parametrize("a,b",[("c","d"),("e","f")])
def test_parametrize(a,b):
    print(a,b)
python 复制代码
import pytest

#列表形式
@pytest.mark.parametrize("name,word",[["安琪拉","魔法师"], ["鲁班","射手"],["亚瑟","肉"]])
def test_parametrize02(name,word):
    print(f'{name}的职业是{word}')

#元组形式
@pytest.mark.parametrize("name,word", [("安琪拉", "魔法师"), ("鲁班", "射手"), ("亚瑟", "肉")])
def test_parametrize02(name, word):
    print(f'{name}的职业是{word}')

#字典形式
@pytest.mark.parametrize("hero", [{"name":"魔法师",}, {"name": "射手"}, {"name": "肉"}])
def test_parametrize02(hero):
    print(hero["name"])
总结
  1. 多参数循环 @pytest.mark.parametrize("a,b",("c","d"),("e","f"))
相关推荐
卷无止境10 分钟前
Guardrails.ai:为大语言模型加一道"安全阀"
后端·python
汤姆小白5 小时前
01-环境搭建与项目导览
人工智能·python·机器学习·numpy
向日的葵00611 小时前
langchain的Tools教程(三)
python·langchain·tools
言乐612 小时前
Python实现可运行解密游戏游戏框架
python·游戏·小程序·游戏程序·关卡设计
YUS云生12 小时前
Python学习笔记·第31天:FastAPI入门——路由、路径参数、查询参数与请求体
笔记·python·学习
智写-AI13 小时前
真实有效的免费降英文AI工具服务商
人工智能·python
yuhuofei202113 小时前
【Python入门】了解掌握Python中函数的基本使用
python
白帽小阳14 小时前
2026前端面试题!(附答案及解析)
javascript·网络·python·安全·web安全·网络安全·护网行动
乱写代码15 小时前
Python开发技巧--类型注解Literal
python