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")])
相关推荐
猫头虎32 分钟前
如何查看局域网内IP冲突问题?如何查看局域网IP环绕问题?arp -a命令如何使用?
网络·python·网络协议·tcp/ip·开源·pandas·pip
沿着路走到底39 分钟前
python 基础
开发语言·python
烛阴2 小时前
武装你的Python“工具箱”:盘点10个你必须熟练掌握的核心方法
前端·python
杨枝甘露小码3 小时前
Python学习之基础篇
开发语言·python
我是华为OD~HR~栗栗呀3 小时前
23届考研-Java面经(华为OD)
java·c++·python·华为od·华为·面试
小蕾Java4 小时前
PyCharm 软件使用各种问题 ,解决教程
ide·python·pycharm
Lucky_Turtle4 小时前
【PyCharm】设置注释风格,快速注释
python
唐古乌梁海4 小时前
【pytest 】 pytest 生命周期
pytest
kunge1v54 小时前
学习爬虫第四天:多任务爬虫
爬虫·python·学习·beautifulsoup
萧鼎4 小时前
Python schedule 库全解析:从任务调度到自动化执行的完整指南
网络·python·自动化