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"))
相关推荐
happylifetree4 小时前
Python67:核心语法-函数进阶-参数类型(函数作为参数)
python
小羊没烦恼!4 小时前
铁道部新客票系统设计(二)
开发语言·前端·数据库·python·oracle·c#·php
quantdash_cc5 小时前
从实时行情到价格观察表:用 Python 和 Pandas 构建策略输入数据
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
镜子AI5 小时前
镜子AI工程实践:用 Python 做 GEO 实体一致性审计,并自动生成 JSON-LD 结构化数据
人工智能·python·json
2601_962885729 小时前
如何用 Python 计算 VaR 和 CVaR(在险价值)?
开发语言·python
李航198310 小时前
DeepSeekAI建模三 - 实战建模一组柜子
人工智能·python·计算机视觉·ai·ai编程
严谨的麻辣烫11 小时前
静态代理 IP 的出口一致性如何验证?Python 请求检测与异常排查
开发语言·python·http·网络安全
我命由我1234511 小时前
5-1.Python 编码进阶 - 函数进阶(参数、返回值、递归、函数作为参数传递、lambda 匿名函数)
java·服务器·数据库·后端·python·java-ee·python3.11
FITA阿泽要努力11 小时前
Fork Agent:共享上下文的艺术
开发语言·python·agent
DeeGLMath12 小时前
optimtool最新版研究梯度优化
python·optimtool·梯度优化