模块四 参数化用例

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)

 

posted on 2021-01-25 19:38  Cc01  阅读(75)  评论(0编辑  收藏  举报

导航