key异常问题
来源:10-8 项目实战之数据依赖调试及组装
qq_精慕门8524681
2020-03-31
老师,上次问key错误这个问题,你回答的我还是不懂,然后我回复了你没看到,下面是截屏和我的代码。。
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]
if is_run == ‘yes’:
is_depend = data[3]
data = json.loads(data[7])
if is_depend:
depend_key = data[4]
depend_data = get_data(is_depend)
data[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=data,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())
2回答
-
慕丝8021493
2020-04-01
不知道你解决没,data被重新赋值了 ,变成了字典,执行data[4]就会报错
1、data是整行的数据,要取用例中的参数不要用相同的变量名,可以用param = json.loads(data[7])
2、取依赖key:depend_key = data[4]
3、更新参数中对应key的值:param[depend_key] = depend_data
112020-04-01 -
Mushishi
2020-03-31
你去把你的data打印出来,看一下你data是什么。你看一下你data里面有没有4这个key。肯定没有啊。我们data获取是data['key']这样的,但是你data[4] 这个data显而易见是list。你去看一下你是不是对象搞错了。
00
相似问题