栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

读取excle文件流程

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

读取excle文件流程

存储数据 (xlsx)

读取数据(readDemo)

读取数据内容源代码:

from openpyxl import load_workbook class UseExcel (): def get_TestExcel ( self ): # 打开表 workbook = load_workbook ( 'D:installpythonpythonTest_allureDataDemo/test1.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 请求接口返回状态码

request请求返回状态码源码 :

import requests from readDataDemo . readexcel import UseExcel class Use_Requestexcel (): def qualification_add ( self ): t = UseExcel () f = t . get_TestExcel () item =[] for excel_i in f : if excel_i [ "method" ] == "get" : rr = requests . get ( excel_i [ "url" ], params = excel_i [ "params" ]) item . append ( rr . status_code ) else : rr = requests . post ( excel_i [ "url" ], data = excel_i [ "params" ]) item . append ( rr . status_code ) return item if __name__ == "__main__" : c = Use_Requestexcel (). qualification_add () print ( c ) pytest 断言设置并结合 allure 生成测试报告

源码展示: 

import pytest , os import allure from userequestsDemo . requestexcel import Use_Requestexcel t = Use_Requestexcel () f = t . qualification_add () for i in f : print ( i ) class Test ( object ): def test_001 ( self ): for aa in f : assert aa == 200 if __name__ == "__main__" : # 生成测试报告 json pytest . main ([ "-s" , "-q" , '--alluredir' , 'report/result' , 'test_03excel.py' ]) # 将测试报告转为 html 格式 split = 'allure ' + 'generate ' + './report/result ' + '-o ' + './report/html ' + '--clean' os . system ( 'cd D:installpython/pythonTest_allureTest/testreport' ) os . system ( split ) 测试报告展示:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/316725.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号