TA的每日心情 擦汗 3 小时前
签到天数: 527 天
连续签到: 4 天
[LV.9]测试副司令
1 测试积点
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)[0]==case_name:
data1=eval(sheet.row_values(i)[2])
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)[0]=='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()) 复制代码
我来回答