def CloseLogger(logger): """ 关闭日志 :param logger: 日志logger :return: None """ close_logger(logger)
def OnCloseWindowAuto(self): """ 关闭窗口,同时跟testlink服务器联动 :return: None """ close_logger(self.logger) self.logger = None self.thread1.stop() self.parent.childnamelist.remove(self.pagename) if self.childid < 10: self.parent.countlist.append(self.childid) self.parent.countlist.sort() time.sleep(0.5) self.Destroy()
def OnCloseWindow(self, evt): """ 关闭窗口,同时后续扩展响应关闭窗口的事件,同时跟testlink服务器联动 :param evt: 关闭串口 :return: None """ DautoTestlinkOperate().tl_on_close_window() close_logger(self.logger) self.logger = None self.thread1.stop() self.parent.childnamelist.remove(self.pagename) if self.childid < 10: self.parent.countlist.append(self.childid) self.parent.countlist.sort() time.sleep(0.5) self.Destroy()
def create_muliti_device_logs(sutlist, test_name, prefix=''): """ 给sutlist里面的设备根据指定test_name创建指定路径的日志 :param sutlist: 设备列表 :type sutlist: list :param test_name: test_case名称 :type test_name: string :param log_list: 记录logger句柄的list,用户全局管理创建的日志 :param prefix: 日志前缀 :type prefix: string :return: None :rtype: """ var = { pc1: pc1_host, sta1: sta1_host, sta2: sta2_host, switch1: switch1_host, switch2: switch2_host, switch3: switch3_host, ap1: ap1_host, ap2: ap2_host } for sut in sutlist: if sut in var.keys(): dev = wx.FindWindowByName(sut) if dev.logger: dev.logger = close_logger(dev.logger) time.sleep(0.1) dev.logger = DcnLog( log_base_path=log_base_path, log_define_type='run', page_name=var[sut], title_name=sut, prefix_log_name=prefix, test_name=test_name).create_log(log_config_file)
def printGlobal(title, switch, msg='', logprefix=''): """ 方案脚本控制-开始计时/结束计时,统计执行信息 说明:此处的函数实现不合理,但是为了兼容原有的实现方式不得已保留,后续可对此进行重构 :param title: s1 s2 :param switch:控制start stop end tlend :param msg: 打印的信息 :param logprefix: 日志前缀 :return: None """ global TESTNAME global TESTNUM global tempTESTNUM global TOTALTESTNUM global tempTOTALTESTNUM global RERUNTESTNUM global FAILLIST global TOTALFAILLIST global STARTTIME global TOTALSTARTTIME global RERUNSTARTTEME global ENDTIME global TOTALENDTIME global RERUNENDTIME global TESTID TESTNAME = title thistime = datetime.datetime.now() mainWin = wx.FindWindowById(10) affirm_tl_operate = mainWin.tl # 获取跟testlink服务器交互句柄 if (switch == 'start') or (switch == 'Start'): TESTID = time.strftime("%Y%m%d", time.localtime()) + str(int(time.time())) mainWin.dbInfo['id'] = TESTID STARTTIME = thistime TESTNUM = 0 FAILLIST = [] res = printFormat(title + ' ' + switch + ' ' + str(thistime), msg) # 开始记录console的log if mainWin.logger: mainWin.logger = close_logger(mainWin.logger) mainWin.logger = DcnLog(log_base_path=mainWin.log_base_path, log_define_type='run', prefix_log_name=logprefix, console_name='console', test_name=TESTNAME).create_log() printAll(res) elif (switch == 'Rerunstart') or (switch == 'RerunStart'): TESTID = time.strftime("%Y%m%d", time.localtime()) + str(int(time.time())) mainWin.dbInfo['id'] = TESTID RERUNSTARTTEME = thistime RERUNTESTNUM = 0 tempTESTNUM = TESTNUM tempTOTALTESTNUM = TOTALTESTNUM FAILLIST = [] res = printFormat(title + ' ' + switch + ' ' + str(thistime), msg) printAll(res) if mainWin.logger: mainWin.logger = close_logger(mainWin.logger) mainWin.logger = DcnLog(log_base_path=mainWin.log_base_path, log_define_type='run', prefix_log_name=logprefix + '[ReRun]', console_name='console', test_name=TESTNAME).create_log() elif (switch == 'end') or (switch == 'End'): ENDTIME = thistime duration = timediff(STARTTIME, ENDTIME) res = printFormat(title + ' ' + switch + ' ' + str(thistime), 'TestCase Duration Time:' + duration) printAll(res) res_str = 'AutoTest Name :' + TESTNAME + '\n' + 'Start Time :' + str(STARTTIME) + '\n' + 'End Time :' + str( ENDTIME) + '\n' + 'Duration Time :' + str(duration) failnum = len(FAILLIST) printAll(res_str) printAll('TestCase : Total ' + str(TESTNUM) + '\n Pass ' + str( TESTNUM - failnum) + '\n Fail ' + str(failnum)) if failnum > 0: printstr = '' printAll('Failed TestCase :') for j in FAILLIST: printstr += str(j) + '\n' printAll(printstr) printAll('') mainWin.dbInfo['totalcases'] = str(TESTNUM) mainWin.dbInfo['passed'] = str(TESTNUM - failnum) mainWin.dbInfo['failed'] = str(failnum) mainWin.dbInfo['knownbugs'] = 'Not available' mainWin.dbInfo['unknowbugs'] = 'Not available' mainWin.dbInfo['failsummary'] = str(FAILLIST) mainWin.dbInfo['suggestions'] = 'Not available' mainWin.dbInfo['starttime'] = str(STARTTIME) mainWin.dbInfo['stoptime'] = str(ENDTIME) mainWin.dbInfo['totaltime'] = str(duration) time.sleep(3) printRes(res_str) printRes('TestCase : Total ' + str(TESTNUM) + '\n Pass ' + str( TESTNUM - failnum) + '\n Fail ' + str(failnum)) if failnum > 0: printstr = '' printResWarn('Failed TestCase :') for j in FAILLIST: printstr += str(j) + '\n' printResWarn(printstr) elif (switch == 'Rerunend') or (switch == 'RerunEnd'): TESTNUM = tempTESTNUM TOTALTESTNUM = tempTOTALTESTNUM RERUNENDTIME = thistime TOTALFAILLIST.extend(FAILLIST) printRes('TOTALFAILLIST={}'.format(TOTALFAILLIST)) duration = timediff(RERUNSTARTTEME, RERUNENDTIME) res = printFormat(title + ' ' + switch + ' ' + str(thistime), 'TestCase Duration Time:' + duration) printAll(res) res_str = 'AutoTest Name :' + TESTNAME + '\n' + 'Start Time :' + str( RERUNSTARTTEME) + '\n' + 'End Time :' + str(RERUNENDTIME) + '\n' + 'Duration Time :' + str(duration) failnum = len(FAILLIST) printAll(res_str) printAll('TestCase : Total ' + str(RERUNTESTNUM) + '\n Pass ' + str( RERUNTESTNUM - failnum) + '\n Fail ' + str(failnum)) if failnum > 0: printstr = '' printAll('Failed TestCase :') for j in FAILLIST: printstr += str(j) + '\n' printAll(printstr) duration = timediff(STARTTIME, RERUNENDTIME) res = printFormat(title + ' ' + switch + ' ' + str(thistime), 'TestCase Duration Time:' + duration) printAll(res) res_str = 'AutoTest Name :' + TESTNAME + '\n' + 'Start Time :' + str(STARTTIME) + '\n' + 'End Time :' + str( RERUNENDTIME) + '\n' + 'Duration Time :' + str(duration) printAll(res_str) printAll('TestCase : Total ' + str(TESTNUM) + '\n Pass ' + str( TESTNUM - failnum) + '\n Fail ' + str(failnum)) if failnum > 0: printstr = '' printAll('Failed TestCase :') for j in FAILLIST: printstr += str(j) + '\n' printAll(printstr) printAll('') mainWin.dbInfo['totalcases'] = str(TESTNUM) mainWin.dbInfo['passed'] = str(TESTNUM - failnum) mainWin.dbInfo['failed'] = str(failnum) mainWin.dbInfo['knownbugs'] = 'Not available' mainWin.dbInfo['unknowbugs'] = 'Not available' mainWin.dbInfo['failsummary'] = str(FAILLIST) mainWin.dbInfo['suggestions'] = 'Not available' mainWin.dbInfo['starttime'] = str(STARTTIME) mainWin.dbInfo['stoptime'] = str(ENDTIME) mainWin.dbInfo['totaltime'] = str(duration) time.sleep(3) printRes(res_str) printRes('TestCase : Total ' + str(TESTNUM) + '\n Pass ' + str( TESTNUM - failnum) + '\n Fail ' + str(failnum)) if failnum > 0: printstr = '' printResWarn('Failed TestCase :') for j in FAILLIST: printstr += str(j) + '\n' printResWarn(printstr) elif switch == 'TlEnd': if mainWin.logger: mainWin.logger = close_logger(mainWin.logger) mainWin.logger = DcnLog(log_base_path=mainWin.log_base_path, log_define_type='run', prefix_log_name=logprefix, console_name='summary', test_name=TESTNAME).create_log() # 创建一个汇总结果的日志文件summary printRes('TOTALFAILLIST{}'.format(TOTALFAILLIST)) TOTALENDTIME = thistime duration = timediff(TOTALSTARTTIME, TOTALENDTIME) res = printFormat(title + ' ' + switch + ' ' + str(thistime), 'TestCase Duration Time:' + duration) printAll(res) res_str = 'AutoTest Name :' + TESTNAME + '\n' + 'Start Time :' + str( TOTALSTARTTIME) + '\n' + 'End Time :' + str(TOTALENDTIME) + '\n' + 'Duration Time :' + str(duration) failnum = len(TOTALFAILLIST) printAll(res_str) printAll('TestCase : Total ' + str(TOTALTESTNUM) + '\n Pass ' + str( TOTALTESTNUM - failnum) + '\n Fail ' + str(failnum)) if failnum > 0: printstr = '' printAll('Failed TestCase :') for j in TOTALFAILLIST: printstr += str(j) + '\n' printAll(printstr) DcnCommonFtp(ftp_config=mainWin.ftp_config_file).upload( mainWin.logfiles) # 日志上传到用户指定服务器,指定服务器配置在config/ftpconfig.json try: if 'job_id' in affirm_tl_operate.tl.__args__ and mainWin.logger and mainWin.logfiles: printResDebug('\ntestlink args are:\n{arg}'.format( arg=json.dumps(affirm_tl_operate.tl.__args__, ensure_ascii=False, indent=4, sort_keys=True))) DcnTestlinkFtp(affirm_tl_operate.tl.__args__, ip=mainWin.ftp_server_ip).upload( mainWin.logfiles) # 日志上传到testlink ftp服务器 recover_args() # testlink/args.py文件恢复初始状态 affirm_tl_operate.set_waffirm_end() # 关闭确认测试平台窗口 except Exception as ex: printResError('error %s' % ex) TOTALTESTNUM = 0 TOTALFAILLIST = []