读取数据(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 ) 测试报告展示:


