Files
jiekou-python3/Public/get_excel.py

46 lines
1.5 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# @Time : 2017/6/4 20:35
# @Author : lileilei
# @File : get_excel.py
2020-11-22 11:23:42 +08:00
import xlrd,os
2020-05-09 21:24:18 +08:00
from Public.log import LOG, logger
2022-01-15 13:44:42 +08:00
@logger('解析测试用例文件')
def datacel(filepath):
2017-10-16 21:00:09 +08:00
try:
2022-01-15 13:44:42 +08:00
file = xlrd.open_workbook(filepath)
print(file)
rslut = file.sheets()[0]
nrows = rslut.nrows
2020-05-09 21:24:18 +08:00
listid = []
listkey = []
listconeent = []
listurl = []
listfangshi = []
listqiwang = []
listname = []
for i in range(1, nrows):
2022-01-15 13:44:42 +08:00
listid.append(rslut.cell(i, 0).value)
listkey.append(rslut.cell(i, 2).value)
listconeent.append(rslut.cell(i, 3).value)
listurl.append(rslut.cell(i, 4).value)
listname.append(rslut.cell(i, 1).value)
listfangshi.append((rslut.cell(i, 5).value))
listqiwang.append((rslut.cell(i, 6).value))
2020-05-09 21:24:18 +08:00
return listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname
2018-09-03 17:30:58 +08:00
except Exception as e:
2022-01-15 13:44:42 +08:00
print(e)
2020-05-09 21:24:18 +08:00
LOG.info('打开测试用例失败,原因是:%s' % e)
return
2020-06-24 09:07:36 +08:00
@logger('生成数据驱动所用数据')
def makedata():
2022-01-15 13:44:42 +08:00
path = os.path.join(os.path.join(os.getcwd(),'test_case_data'),'case.xlsx')
2020-11-22 11:23:42 +08:00
listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname=datacel(path)
2020-06-24 09:07:36 +08:00
i=0
make_data=[]
for i in range(len(listid)):
make_data.append({'url':listurl[i],'key':listkey[i],'coneent':listconeent[i],'fangshi':listfangshi[i],'qiwang':listqiwang[i]})
i+=1
return make_data