没有合适的资源?快使用搜索试试~ 我知道了~
首页python 接口测试response返回数据对比的方法
python 接口测试response返回数据对比的方法
16 下载量 41 浏览量
更新于2023-03-16
评论
收藏 57KB PDF 举报
本篇文章主要介绍了python 接口测试response返回数据对比的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
资源详情
资源评论
资源推荐
python 接口测试接口测试response返回数据对比的方法返回数据对比的方法
本篇文章主要介绍了python 接口测试response返回数据对比的方法,小编觉得挺不错的,现在分享给大家,也
给大家做个参考。一起跟随小编过来看看吧
背景:之前写的接口测试一直没有支持无限嵌套对比key,上次testerhome逛论坛,有人分享了他的框架,看了一下,有些地
方不合适我这边自己修改了一下,部署在jenkins上跑完效果还不错,拿出来分享一下。ps:还是要多看看别人写的,新学了
不少python自带的一些常用方法。
这次直接上代码,下面写一下这次我新学一些方法和思路。
def check_response_hope_key(self,response={},hope_response={}):
temp_data={}
for n1 in hope_response:
print "n1:",n1
#如果值是字典类型
if isinstance(hope_response[n1],dict):
print "dict"
if not Check_Response_Hope().check_response_hope_key(response=response.get(n1), hope_response=hope_response[n1]):
MailFile().checkfail(response=response.get(n1), hope_response=hope_response[n1])
return False
raise '{},{}'.format(hope_response[n1],response[n1])
#如果值是列表类型
elif isinstance(hope_response[n1],list):
print "list"
for hope_index,hope_listValue in enumerate(hope_response[n1]):
#print "hope_index:",hope_index
#print "hope_listValue:",hope_listValue
for response_index,response_listValue in enumerate(response[n1]):
#print "response_index:",response_index
#print "response_listValue:",response_listValue
if isinstance(hope_listValue,dict):
Check_Response_Hope().check_response_hope_key(response=response[n1][response_index],
hope_response=hope_response[n1][response_index])
elif isinstance(hope_listValue,list):
if hope_response[n1][hope_index]==response[n1][hope_index]:
break
else:
MailFile().checkfail(response=response_listValue,hope=hope_listValue)
raise Exception ("hope_response="+str(hope_response[n1][hope_index])+""+
"response="+str(response[n1][response_index]))
else:
if hope_response[n1][hope_index]==response[n1][hope_index]:
break
else:
MailFile().checkfail(response=response[n1][hope_index],hope=hope_response[n1][hope_index])
raise Exception ("hope_response="+str(hope_listValue)+""+"response="+str(response_listValue))
else:
print "string"
if response.has_key(n1):
continue
else:
temp_data['error_data']='{}:{},{}:{}'.format(n1,hope_response[n1],n1,response[n1])
#发送邮件
MailFile().checkfail(response=response[n1],hope=hope_response[n1])
raise Exception ("hope_response="+str(hope_response[n1])+""+"response="+str(response.get(n1)))
return True
内置函数内置函数enumerate():
传入list的数据时返回该列表的索引和值,例如:
>>> list1=[1,2,3,4]
>>> for list_index,list_value in enumerate(list1):
... print list_index,list_value
...
0 1
1 2
2 3
3 4
还可以控制索引的起始值开始迭代,例如:
weixin_38703787
- 粉丝: 5
- 资源: 889
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- ExcelVBA中的Range和Cells用法说明.pdf
- 基于单片机的电梯控制模型设计.doc
- 主成分分析和因子分析.pptx
- 共享笔记服务系统论文.doc
- 基于数据治理体系的数据中台实践分享.pptx
- 变压器的铭牌和额定值.pptx
- 计算机网络课程设计报告--用winsock设计Ping应用程序.doc
- 高电压技术课件:第03章 液体和固体介质的电气特性.pdf
- Oracle商务智能精华介绍.pptx
- 基于单片机的输液滴速控制系统设计文档.doc
- dw考试题 5套.pdf
- 学生档案管理系统详细设计说明书.doc
- 操作系统PPT课件.pptx
- 智慧路边停车管理系统方案.pptx
- 【企业内控系列】企业内部控制之人力资源管理控制(17页).doc
- 温度传感器分类与特点.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0