Pytest | 参数化处理三种类型 [ 列表、元组、字典]

Pytest参数化测试上期我们介绍到Python自动化测试 | Pytest之参数化 常用的用法如下

@pytest.mark.parametrize("参数名",列表数据)

我们今天在简单的一起学习一下,参数化支持的三种类型

参数化方式支持:列表、元组、字典 三种类型;

我们拿实例代码入参, 一起看一看

# coding=utf-8
# authou:shichao

import pytest

data_lists = [
    [11, 22, 33]
]

test_datas = [
    (11, 22, 33),
    (22, 33, 55)
]

datas_dict = [
    {"a": 1, "b": 2, "c": 3},
    {"a": 11, "b": 22, "c": 33},
    {"a": 111, "b": 222, "c": 333},
]


# 方式一:参数为列表中嵌套列表
@pytest.mark.parametrize("a, b, c", data_lists)
def test_add01(a, b, c):
    res = a + b
    assert res == c


# 方式二:参数为列表中嵌套元组
@pytest.mark.parametrize("data", test_datas)
def test_add02(data):
    res = data[0] + data[1]
    assert res == data[2]


# 方式三:参数为列表中嵌套字典
@pytest.mark.parametrize("data", datas_dict)
def test_add03(data):
    res = data["a"] + data["b"]
    assert res == data["c"]

每天一个小知识点,再忙不忘记充电

加微信:695214599 领取精品测试开发资料,加软件测试划水群

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值