- yaml用例设计--一个yaml中多个用例,且互相存在关联关系
python
- # 第一个用例
request:
method: post
url: http://192.168.0.1:8010/api
json:
accounts: admin
pwd: 123
type: username
headers:
Content-Type: application/json
- # 第二个用例
request:
method: post
url: http://192.168.0.1:8010/api/order/index
headers:
Content-Type: application/json
- 设计多接口用例读取封装
python
def read_testcase(yaml_path):
with open(yaml_path,encoding="utf-8") as f:
case_list = yaml.safe_load(f)
if len(case_list) >=2: # list长度大于等于2,则说明是多个接口用例,则yaml读取出来的格式为:[{},{}]
return [case_list] # 将返回格式修改为[[{},{}]]
else:
return case_list # 单接口的用例格式,直接返回即可:[{}]
- 将读取caseinfo的方法进行list格式的兼容设计
python
def create_testcase(yaml_path):
@pytest.mark.parametrize('caseinfo', read_testcase(yaml_path))
def func(self,caseinfo):
global case_obj
if isinstance(caseinfo,list): # 多接口用例
for case in caseinfo:
case_obj = verify_yaml(case)
stand_case_flow(case_obj)
else: # 单接口用例
# 校验yaml中的数据
case_obj = verify_yaml(caseinfo)
# 用例的标准化流程
stand_case_flow(case_obj)
return func