模块四 参数化用例

pytest数据参数化

参数化使用

 使用string

import  pytest

@pytest.mark.parametrize("a,b",[
    (1,2),
    (10,20),
    (100,200)
])

class TestDemo:
    def test_param(self,a,b):
        print(a+b)

使用list

import  pytest

@pytest.mark.parametrize(['a','b'],[
    (1,2),
    (10,20),
    (100,200)
])

class TestDemo:
    def test_param(self,a,b):
        print(a+b)

使用touple

import  pytest

@pytest.mark.parametrize(('a','b'),[
    (1,2),
    (10,20),
    (100,200)
])

class TestDemo:
    def test_param(self,a,b):
        print(a+b)

yaml参数

yaml实现list

yaml实现字典

yaml进行嵌套

加载yaml文件

import  pytest
import yaml


@pytest.mark.parametrize("a,b",yaml.safe_load(open("./date.yaml")))

class TestDemo:
    def test_param(self,a,b):
        print(a+b)
原文地址:https://www.cnblogs.com/hantongxue/p/14327037.html