国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

python 接口測(cè)試response返回?cái)?shù)據(jù)對(duì)比的方法

2020-02-22 23:14:36
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

背景:之前寫的接口測(cè)試一直沒(méi)有支持無(wú)限嵌套對(duì)比key,上次testerhome逛論壇,有人分享了他的框架,看了一下,有些地方不合適我這邊自己修改了一下,部署在jenkins上跑完效果還不錯(cuò),拿出來(lái)分享一下。ps:還是要多看看別人寫的,新學(xué)了不少python自帶的一些常用方法。

這次直接上代碼,下面寫一下這次我新學(xué)一些方法和思路。

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])+"/n"+"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)+"/n"+"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])     #發(fā)送郵件     MailFile().checkfail(response=response[n1],hope=hope_response[n1])     raise Exception ("hope_response="+str(hope_response[n1])+"/n"+"response="+str(response.get(n1)))      return True

內(nèi)置函數(shù)enumerate():

傳入list的數(shù)據(jù)時(shí)返回該列表的索引和值,例如:

>>> 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

還可以控制索引的起始值開始迭代,例如:

>>> for list_index,list_value in enumerate(list1,1):...  print list_index,list_value...             
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 雷州市| 仙游县| 嘉定区| 嘉兴市| 阳东县| 句容市| 白沙| 宜君县| 阿鲁科尔沁旗| 龙岩市| 阿坝县| 宜兰市| 文昌市| 老河口市| 三河市| 达拉特旗| 平江县| 和静县| 南乐县| 自贡市| 繁峙县| 永清县| 金沙县| 哈巴河县| 河东区| 玉溪市| 祁门县| 南郑县| 扶沟县| 兰坪| 扶余县| 乐都县| 乌兰浩特市| 师宗县| 台南市| 五家渠市| 泰兴市| 大姚县| 南丹县| 浙江省| 伽师县|