python接口ddt处理excel读取出来的参数
python接口ddt处理excel读取出来的参数1、单独读取data一列,我这边会ddt处理掉
<strong>def excel_data(case_name):
book=xlrd.open_workbook('C:/request/case/case.xls')
sheet= book.sheet_by_name('Sheet1')
data=[]
for i in range(0,sheet.nrows):
if sheet.row_values(i)==case_name:
data1=eval(sheet.row_values(i))
data.append(data1)
return data</strong>2、现在读取一行,然后使用ddt处理到接口请求中,不知如何做?
def excel_data(y):
book=xlrd.open_workbook('C:/request/case/case.xls')
sheet= book.sheet_by_name('Sheet1')
data=[]
for i in range(0,sheet.nrows):
if sheet.row_values(i)=='y':
#sheet.row_values(i))
data.append(sheet.row_values(i))
return data读取出来的结果:
<strong>[['y', 'https://i299.2b.cn', "{'userAccount':'18221124101','verifyCode':'3979'}", "{"Content-Type'': "application/json"}"], ['y', 'https://i299.2b.cn', "{'userAccount':'18221124103','verifyCode':'3979'}", "{"Content-Type'': "application/json"}"], ['y', 'https://i299.2b.cn', "{'userAccount':'18221124104','verifyCode':'3979'}", "{"Content-Type'': "application/json"}"]]
@ddt.ddt
class Test(unittest.TestCase):
'''登录'''
data=excel.excel_data('y')
def setUp(self):
pass
def tearDown(self):
pass
@ddt.data(*data)
@unpack</strong>
我这里要带入url和data怎么做,我这样做应该错的?
def test1(self,data):#封装登录函数
r=requests.post(url,headers,data)
print(r.json())
页:
[1]