添加依赖字段提示异常:列表索引超出范围
来源:10-8 项目实战之数据依赖调试及组装
qq_精慕门8524681
2020-04-01
老师,请问下我在excel表中添加了依赖字段的数据后,进行运行代码就会报错,提示:IndexError:列表索引超出范围。。。。如果不添加依赖字段,接口就可以正常运行,你帮忙看看什么原因,下面是我的代码和截图
class RunMain:
def run_case(self):
rows = excel_data.get_row()
for i in range(rows):
cookie = None
depend_data = None
data = excel_data.get_row_value(i+2)
is_run = data[2]
is_depend = data[3]
param = data[7]
if is_run == ‘yes’:
if is_depend:
depend_key = data[4]
depend_data = get_data(is_depend)
param[depend_key] = depend_data
method = data[6]
url = data[5]
excepect_method = data[11]
excepect_result = data[12]
head = data[8]
if head == 'yes':
head = get_header()
res = request.run_main(method=method,url=url,data=param,header=head,cookie=cookie)
print(res)
code = res['state']
message = res['success']
message = str(message)
code = res['state']
message = res['success']
message = str(message)
if excepect_method == "mec":
config_message = handle_result(url, "state")
config_message1 = handle_result(url, "success")
if code == config_message and message == config_message1:
excel_data.excel_write_data(i + 2, 14, "通过")
else:
excel_data.excel_write_data(i + 2, 14, "失败")
excel_data.excel_write_data(i + 2, 15, json.dumps(res))
if excepect_method == "errorcode":
if code == excepect_result:
excel_data.excel_write_data(i + 2, 14, "通过")
else:
excel_data.excel_write_data(i + 2, 14, "失败")
excel_data.excel_write_data(i + 2, 15, json.dumps(res))
if excepect_method == "json":
if code == "1":
get_result = get_result_json(url, "data")
reslut = handle_result_json(res["data"], get_result)
if reslut == True:
excel_data.excel_write_data(i + 2, 14, "通过")
else:
excel_data.excel_write_data(i + 2, 14, "失败")
excel_data.excel_write_data(i + 2, 15, json.dumps(res))
if name == ‘main’:
run = RunMain()
print(run.run_case())
=====================================================================================
def split_data(data):
’’‘
拆分单元格数据
’’'
case_id = data.split(">")[0]
rule_data = data.split(">")[1]
return case_id,rule_data
def depend_data(data):
’’‘
获取依赖结果集
’’'
case_id = split_data(data)[0]
row_number = excel_data.get_rows_number(case_id)
data = excel_data.get_data_value(row_number,15)
return data
def get_depend_data(res_data,key):
’’‘
获取依赖字段
’’’
#res_data = json.loads(res_data)
json_exe = parse(key)
madle = json_exe.find(res_data)
return [math.value for math in madle][0]
def get_data(data):
’’‘
获取依赖数据
’’'
res_data = depend_data(data)
rule_data = split_data(data)[1]
return get_depend_data(res_data,rule_data)
1回答
-
Mushishi
2020-04-02
你把你需要依赖得key 和返回得结果拿来对比以下就知道了呀。我看你这个是不对得。
022020-04-02