?把xlsx文件复制到pycharm里面
?
?读取数据
?
?
from openpyxl import load_workbook
class UseExcel():
def get_TestExcel(self):
# 打开表
workbook = load_workbook('../data/1234.xlsx')
# 定位表单
sheet = workbook['Sheet1']
print(sheet.max_row) #3 行
print(sheet.max_column) #3 列
test_data = []#把所有行的数据放到列表中
for i in range(2,sheet.max_row+1):
sub_data = {}#把每行的数据放到字典中
for j in range(1,sheet.max_column+1):
sub_data[sheet.cell(1,j).value] = sheet.cell(i,j).value
test_data.append(sub_data)#拼接每行单元格的数据
return test_data
t = UseExcel()
f = t.get_TestExcel()
print(f)
request请求接口返回状态
?
?
import requests
from readdata.readexcel import UseExcel
ue = UseExcel()
lists = ue.get_TestExcel()
litem=[]
class RequestsExcelClass:
def requestsExcelMethod(self):
for excal_i in lists:
if excal_i.get("method") == "get":
r = requests.get(url=excal_i["url"],params=excal_i["params"])
litem.append(r.status_code)
else:
r = requests.get(url=excal_i["url"], data=excal_i["params"])
litem.append(r.status_code)
return litem
r = RequestsExcelClass()
print(r.requestsExcelMethod())
pytest断言设置并结合allure生成测试报告
?正确的:
?
?失败的:
?
?
import pytest,os,allure
from requestsdemo.requestsexcel import RequestsExcelClass
r = RequestsExcelClass()
listd = r.requestsExcelMethod()
class TestExcelClass:
def testExcelClass(self):
for excel_i in listd:
assert excel_i == 200
if __name__ == '__main__':
pytest.main(['--alluredir', 'report/result', 'test_requstsexcel.py'])
split = 'allure ' + 'generate ' + './report/result ' + '-o ' + './report/html ' + '--clean'
os.system(split)
|