def all_cases(self, all_cases): """ 所有用例数据 :return: """ self.r.lpush('{}_all_cases'.format(self.env), json.dumps(all_cases)) #json.dumps编译成json字符串 Loging().info('插入数据成功')
def all_times(self, all_times): """ 从左边插入用例时间 :param all_time: :return: """ self.r.lpush('{}_all_times'.format(self.env), all_times) Loging().info('成功插入用例时间')
def __init__(self): redis_ip = MyYaml().config('redis_ip') redis_port = MyYaml().config('port') pool = redis.ConnectionPool(host=redis_ip, port=redis_port, decode_responses=True, db=0) self.r = redis.Redis(connection_pool=pool) # Loging().info('链接redis成功') self.env = MyYaml().config('env') self.log = Loging()
# def test_login(self, url, data): # r = requests.post(url=url, data=data, timeout=5) # self.result = r.json() # print(self.result) # # if __name__ == '__main__': # Login().test_login() # a = '1,2,3,4,5' # c = list(a) # print(c) # print(r'\b') # print('\b') import random from myloging import Loging log = Loging() a = [1, 2, 3, 4] b = [[1, 2], [2, 5], [3, 6], [7, 8]] sum1 = 0 sum2 = 0 cls = [] for i in a: s = 0 for x in b: c = i in x cls.append(c) s += 1 if s == 4: if True in cls: sum1 += 1 log.info('原始网段%s包含在合并网段中' % i)
# # # if os.path.exists(init_file_py): #os.path.exists(init_file_py):判断是否存在文件或目录init_file_py # # os.remove(init_file_py) #os.remove(file):删除一个文件 # all_moudle = str(all_moudle) # import re # # all_moudle = re.sub("'", '', all_moudle) # # print(all_moudle) # with open(init_file_py, 'w') as f: # f.writelines(all_import_class) # f.write('moudle_list = {}'.format(all_moudle)) # f.write('\n') # f.close() # # print(all_moudle,moudle_list) # # all_moudle, moudle_list = moudle_name() from Case import moudle_list from myloging import Loging log = Loging() from models.myunit_per import ReadYaml from read_writeyaml import MyYaml from models.MyRedis import Myredis as redis # redis.all_module(moudle_list) #存进redis #创建新线程 dmps = MyYaml().baseData('report_cases') a = MyYaml().config('ip') print(a) print(dmps)
import IPy from myloging import Loging import requests import random import json from models.Read_xls import readExcel log = Loging() from configpath import getpath import os import datetime import threading import numpy import time path = getpath() pa = os.path.join(path, 'XY_test', 'file.txt') data = readExcel().get_xls('case_xy_huawei.xlsx', 'Sheet4') data1 = readExcel().get_xls('case_xy_huawei.xlsx', 'Sheet5') class myThread(threading.Thread): #继承父类threading.Thread def __init__(self, threadID, number, name): threading.Thread.__init__(self) self.threadID = threadID self.number = number self.name = name def run(self): log.info('开启线程:{}'.format(self.name), ) HW_test().test_hw(self.number) log.info('{}线程结束!'.format(self.name))
import requests from models.myunit import mytest from myloging import Loging from read_writeyaml import MyYaml import ddt from models.Read_xls import readExcel logg = Loging() import unittest from models import HTMLTestRunner from configpath import getpath import os report1 = os.path.join(getpath(), 'result', 'GetRouteList.html') @ddt.ddt class GetRouteList_auth(unittest.TestCase): """获取游戏路由表接口""" data = readExcel().get_xls('case_xy_huawei.xlsx', 'GetRouteList') @ddt.data(*data) def test_auth_GetRouteList(self, data): """获取游戏路由表""" r = requests.post(MyYaml().config('url') + data.url, data.datas, stream=True) self.result = r.json() time1 = r.elapsed.total_seconds() print('接口响应时间:' + str(time1)) logg.info('第{}条用例执行'.format(data.id)) logg.info('用例名称:{}'.format(data.name)) logg.info('接口响应时间为:{}'.format(time1))
class mytest(unittest.TestCase): #可参数化的类 def __init__(self, methodName='runTest', param=None): super(mytest, self).__init__(methodName) self.param = param log = Loging() result = None global case_count case_count = 0 @classmethod def setUpClass(self): self.key_list = {} @classmethod def tearDownClass(self): pass def setUp(self): print('adfafaff') # self.className = self.__class__.__name__ # self.module = self.__class__.__module__ # self.case_info = self._testMethodName #接口方法名、self._testMethodName用来获取方法名 # self.key = self.className.split('_')[1] # self.datas = MyYaml().interface_data[self.key] # self.data = [] # self.dataall = [] # self.case_name = [] # for i in self.datas: # if i['className'] == self.className: # self.data.append(i['url']) # api地址 0 # for j in i['funName']: # for k in j.keys(): # if k == self.case_info: # self.data.append(j[self.case_info]['bar']) #参数 1 # self.data.append(j[self.case_info]['result']) #预期结果 2 # self.data.append(j[self.case_info]['mode']) #请求方式 3 # self.data.append(j[self.case_info]['test_data']) #接口时间 -1 # self.case_name.append(i['name']) # self.dataall.append(self.data) # # print(self.dataall) # # del self.data[-5:] # # print(self.data) # # print(self.dataall) # if not isinstance(self.data[1], list): # self.data[1] = dict(self.data[1], **self.key_list) # self.url = MyYaml().config('url') + self.data[0] # # try: # token = read_ini(node='session', child='access_token') #重配置文件获取token # except Exception: # token = '0' # self.headers = {'Authorization': 'Bearer{}'.format(token)} #请求头 # # def tearDown(self): # try: # parameter = self.result['status'] # except Exception: # parameter = '' # try: # msg = self.result['msg'] # except Exception: # msg = '' # # Response = results( # name=self.case_name[0], # expected=self.data[2][0], # actual=parameter, # method=self.data[3], # address=self.data[0], # parameter=self.data[1], # Results=self.result, # time_count=getTimeCount(str(self.data[-1])), #接口响应时间 # ) # Response = json.dumps(Response, indent=4, ensure_ascii=False) # #保存redis # print(Response) # redis.case_data([self.case_info, Response]) #测试数据缓存redis # self.log.debug( # '%s->%s->%s: 传参:%s' % ( # self.module, # self.className, # self.case_info, # self.data[1], # ) # ) # self.log.debug('%s->%s->%s: 返回结果:%s' % ( # self.module, # self.className, # self.case_info, # self.result, # ) # ) # self.log.debug('{} 验证完毕'.format(self.case_name[0])) # self.assertEqual(self.data[2][0], parameter, msg=msg) #断言 # print("用例执行结束。。。") @staticmethod #装饰静态方法、静态方法调用无需实例化 def parametrize(testcase_klass, param=None): #参数化方法 """ Create a suite containing all tests taken from the given subclass, passing them the parameter 'param'. """ testloader = unittest.TestLoader() testnames = testloader.getTestCaseNames(testcase_klass) suite = unittest.TestSuite() for name in testnames: suite.addTest(testcase_klass(name, param=param)) # print('测试套件为:{}'.format(suite)) print('这是我的mytest') return suite