class TestCase(unittest.TestCase): # 1、获取数据 a = readExcel.ReadExcel() excel_list = a.getExcelList() # print(type(excel_list)) # print(excel_list) #2、发送请求 @data(*excel_list) @unpack def test_normal(self, id, url, path, method, data, expect): print(id, url, path, method, data, expect) res = confighttp.GetResponse().sendRequest(method, url, data) print("返回", res) real = res['errorCode'] print(real, expect) #3、断言结果 wr = writeExcel() try: self.assertEqual(str(real), str(expect)) reaslt = 'Success' print(reaslt) except AssertionError as m: reaslt = 'Error' print(reaslt) #4、写入文件 print('info', id, real, reaslt, type(id), type(real), type(reaslt)) wr.writeData(int(id), real, reaslt)
import os import unittest import json import paramunittest from common import readExcel, readConfig, requestResult, getPath base_url = readConfig.GetConfig().url # 取得base url test_case_file = readConfig.GetConfig().test_case_file # 取得测试用例excel文件名 case_sheet = readConfig.GetConfig().case_ptl_towerContain # 取得excel的sheet名 case_xls = readExcel.ReadExcel().get_xls(test_case_file, case_sheet) @paramunittest.parametrized(*case_xls) class test_ptl_tower_control(unittest.TestCase): def setParameters(self, case_name, path, method, headers, param, status_code, expectation, remark): """ set params :param case_name: :param path: :param method: :param headers: :param param: :param status_code: :param expectation: :param remark: :return: """ self.case_name = str(case_name) self.path = str(path)