ui自动化用例数据存储方式考虑使用yaml文件,简单的学习下

 

1、yaml 文件

#单独参数
datas:
- 1
- 5
#多参数方式一
groups:
- [1,2]
- [2,3]
#多参数方式二
groups2:
-
- 1
- 2
- 3
2、demo

class TestPyt:
    #一个参数
#测试的类需要以test开头
# 读取yaml文件
with open('D:/automated_testing/test_cases/pra.yaml') as f:
data = yaml.safe_load(f)
print(data['groups'])

@pytest.mark.parametrize('a',data['datas'])
def test_a(self,a):
print('测试a',a)
assert 1


@pytest.mark.parametrize('a,b,c', data['groups2'])
def test_b(selef, a, b, c):
print('测试b', a, b, c)
assert 2

@pytest.mark.parametrize('a,b', data['groups'])
def test_c(selef, a, b):
print('测试c', a, b)
assert 2

if __name__ == '__main__':

pytest.main(["-s", "test.py"])
3、测试结果如图所示

 


 

 
posted @ 2021-07-01 09:12  AINOUSVA  阅读(263)  评论(0)    收藏  举报