pytest 参数化 1.parametrize 2.yaml

1.1 安装pytest

1.2 格式如下, 写入装饰器

@pytest.mark.parametrize(
"platform",
['data1','data2','data3'],
ids=['description1','description2','decription3']
)
def func():
  pass

2.yaml

2.1 yaml 格式

[注意]yaml分层只能用空格,不能用Tab

dict格式

data1: description1

data2: decription2

list格式

- description1

- description2

混合格式

data1: 

  data2: 

    - description1

    - description2

  data3:

    - description1

    - description2

2.2 py 获取yaml文件内容

with open('./data.yaml')as f:
testdata = yaml.load(f, Loader=yaml.SafeLoader)

使用parametrize 读取

@pytest.mark.parametrize(
"platform",
testdata['data1']['data2'],
ids=testdata['data1']['data3']
)
def func():
  pass