def __init__(
         self,
         filename,
         filelevel='debug',
         streamlevel='info',
         when='D',
         interval=1,
         backupCount=10,
         fformatter='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s - %(message)s',
         sformatter='%(asctime)s - %(message)s'):
     project_path = cur_path()
     self.folder = os.path.join(project_path, 'logs')
     mkdir(self.folder)
     self.filename = os.path.join(self.folder, filename)
     # set logger format
     self.file_formatter = logging.Formatter(fformatter)
     self.stream_formatter = logging.Formatter(sformatter)
     self.filelevel = filelevel
     self.streamlevel = streamlevel
     self.when = when
     self.interval = interval
     self.backupcount = backupCount
     self.logger = logging.getLogger(self.filename)
     self.logger.setLevel(self.level_relations.get(
         self.filelevel))  # set logger level
Esempio n. 2
0
def run(suite):
    report = ''
    test_description = "<p>[ORACLE 数据库]</p><p style='text-indent:0.5'><strong>DB_Connection:</strong> {}</p> " \
                       "<p style='text-indent:0.5'><strong>DB_User:</strong> {}</p> " \
                       "<strong><p style='text-indent:0.5'>DB_Password:</strong> {}</p> " \
                       "<br><p>[接口]</p> <p style='text-indent:0.5'><strong>Api:</strong> {}</p> " \
                       "<p style='text-indent:0.5'><strong>Api_Key:</strong> {}</p>"\
                        .format(database_connection_url, database_user, database_password, api_url, api_key)
    cur_time = time.strftime('%Y%m%d_%H%M%S', time.localtime())
    if report_path is '' or report_path is None:
        project_path = cur_path()
        mkdir(os.path.join(project_path, 'report'))
        report = os.path.join(
            project_path, 'report',
            'ESPOS82_Promotion_AutoTest_{}.html'.format(cur_time))
    elif not report_path.endswith('.html'):
        logger.info(
            'report path: {}配置有误,正确格式如: D:\\report.html'.format(report_path))
        return
    else:
        report = re.sub(r'\.html', '_{}.html'.format(cur_time), report_path)
    with open(report, 'wb') as fp:
        HTMLTestRunner(stream=fp,
                       verbosity=2,
                       title="测试报告",
                       description="",
                       test_description=test_description).run(suite)
 def __init__(
         self,
         logger_name='mylog',
         file_name=None,
         log_file=1,
         level='debug',
         when='D',
         interval=1,
         backupCount=10,
         encoding='utf-8',
         fformatter='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s - %(message)s',
         sformatter='%(asctime)s - %(message)s'):
     super().__init__(logger_name)
     self.logger = logging.getLogger(logger_name)
     self.logger.propagate = False
     stream_formatter = logging.Formatter(sformatter)  # set logger format
     self.logger.setLevel(level)  # set logger level
     # sh = logging.StreamHandler()
     # sh.setLevel(level)
     # sh.setFormatter(stream_formatter)
     # self.logger.addHandler(sh)
     if log_file:
         project_path = cur_path()
         folder = os.path.join(project_path, 'logs')
         file_name = os.path.join(folder, file_name)
         mkdir(folder)
         self.th = handlers.TimedRotatingFileHandler(
             filename=file_name,
             when=when,
             interval=interval,
             backupCount=backupCount,
             encoding=encoding)  # separate file by time
         file_formatter = logging.Formatter(fformatter)
         self.th.setLevel(level)
         self.th.setFormatter(file_formatter)
         self.logger.addHandler(self.th)
Esempio n. 4
0
from frozen_path import cur_path
import json as js
import os


project_path = cur_path()
model_base_json_path = os.path.join(project_path, 'json_model\\base\\base.json')


# TODO 对比两个json串所有层级
def compare_json_key(test_cls, data_base_json, model_base_json_path):
    data_json_keys = []
    model_json_keys = []
    data_base_json = js.loads(data_base_json)
    for key in data_base_json.keys():
        data_json_keys.append(key)
    with open(model_base_json_path, 'r', encoding='utf-8') as f:
        model_json = js.load(f)
        for key in model_json.keys():
            model_json_keys.append(key)
    if data_json_keys != model_json_keys:
        test_cls.skipTest('请检查config.ini [JsonModel] 下的BaseJson 是否正确配置')
    return data_base_json