YAML里的值用参数化处理,避免测试数据量大时,整个YAML文件也很大,测试数据写在CSV文件里。也算是自动化测试框架中的一部分吧。
整个思路是这样的:
1、准备CSV文件,写好测试数据
name,appid,secret,grant_type,assert_str
first_case,id1,secret1,grant_type1,errcode1
second_case,"",secret2,grant_type2,errcode2
third_case,id3,"",grant_type3,errcode3
forth_case,id4,secret4,"",errcode4
fifth_case,id5,secret5,"",errcode5
sixth_case,id6,secret6,"",errcode6
2、解析CSV文件,转化成JSON格式
import csv
import json
from contextlib import ExitStack
"""
将csv文件转换成json
"""
profileList = []
def FromCsvToJson(csv_path):
with open(csv_path, 'r', encoding='utf-8') as csv_file:
reader = csv.DictReader(csv_file)
for row in reader:
profileList.append(dict(row))
return profileList
可以看出就是个字典列表