从excel、txt、dict中取data,预期值

一:从excel中取data

excel中放入预期值,上报data数据

excel中第一行是data数据,第二行是预期值

在每个class中,取data数据上报到接口中,具体代码如下:

def getpost2():
data=xlrd.open_workbook('D:\test.xlsx')
table=data.sheets()[0]
nrows=table.nrows
for i in range(nrows):
postdata=table.cell(i,0).value
yq=table.cell(i,1).value
url='http://******************************'
header={'Content-Type' : 'application/xml','charset':'UTF-8'}
response=requests.post(url,data=postdata,headers=header)
if yq in response.text:
print 'pass'
else:print 'faild'

说明:若第一行为列明,则for循环中的range为(1,nrows)

二、从dict中取data和预期值
a={'datapostA':'yuqijieguoA','datapostB':'yuqijieguoB'}
for data,yq in a.items():
response=requests.post(url,data,headers=***)

三、从文件中获取data和预期值
在txt中写入data和预期值,使用,分开
filedata=file('文件地址')
for i in filedata.readLines:
post=i.split(',')
data=i[0]

yq=i[1]

原文地址:https://www.cnblogs.com/344525813xiang/p/6655043.html