Asserttion斷言分裝===================== #1.等于---0.包含 from unit.operExcle import operExcle def Assert(row,cell,per,act): oper= operExcle() value = oper.get_value(row=row,cell=cell) flag= False if value==None: return True if value == 1 : try: assert per == act flag = True return flag except Exception as e: return flag elif value == 0: try: assert per in act flag = True return flag except Exception as e: return flag if __name__ =="__main__": a=Assert(0,"niha","nihao") print(a) logging 日志封裝========== import logging import os,time from datetime import datetime class Logger: def __init__(self, name=__name__): # 創(chuàng)建一個loggger self.__name = "UI自動化執(zhí)行日志" self.logger = logging.getLogger(self.__name) self.logger.setLevel(logging.DEBUG) # 創(chuàng)建一個handler,用于寫入日志文件 logname = '../log/out/'+str(time.time())+'_out.log' # 指定輸出的日志文件名 # fh = logging.handlers.TimedRotatingFileHandler(logname, when='M', interval=1, backupCount=5,encoding='utf-8') # 指定utf-8格式編碼,避免輸出的日志文本亂碼 fh = logging.FileHandler(logname, mode='w', encoding='utf-8') # 不拆分日志文件,a指追加模式,w為覆蓋模式 fh.setLevel(logging.DEBUG) # 創(chuàng)建一個handler,用于將日志輸出到控制臺 ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) # 定義handler的輸出格式 formatter = logging.Formatter('%(asctime)s-%(name)s-[line:%(lineno)d]' '-%(levelname)s-[日志信息]: %(message)s', datefmt='%a, %d %b %Y %H:%M:%S') fh.setFormatter(formatter) ch.setFormatter(formatter) # 給logger添加handler self.logger.addHandler(fh) self.logger.addHandler(ch) @property def get_log(self): """定義一個函數(shù),回調(diào)logger實例""" return self.logger log = Logger(__name__).get_log |
|