def _get_log():
    '''
    通过YamlUtil类获取yaml字典
    通过字典中的参数生成日志对象
    :return: 日志对象
    '''
    yaml_dict = YamlUtil.get_yaml()
    #使用导航方式获得配置文件中的参数
    name = CommonUtil.get_value_by_navigate_from_dict(yaml_dict, "log.name", "myLog")
    format = CommonUtil.get_value_by_navigate_from_dict(yaml_dict, "log.format", "%(asctime)s %(name)s %(levelname)s %(filename)s line:%(lineno)d %(message)s")
    level = CommonUtil.get_value_by_navigate_from_dict(yaml_dict, "log.level", "INFO")
    file_backup_count = CommonUtil.get_value_by_navigate_from_dict(yaml_dict, "log.file.backupCount", 5)
    file_encoding = CommonUtil.get_value_by_navigate_from_dict(yaml_dict, "log.file.encoding", "utf8")
    file_maxBytes = CommonUtil.get_value_by_navigate_from_dict(yaml_dict, "log.file.maxBytes", 1024)
    if file_maxBytes:
        file_maxBytes = eval(file_maxBytes)
    file_path = CommonUtil.get_value_by_navigate_from_dict(yaml_dict, "log.file.path", "../output/logs/testProject.log")
    file_path = CommonUtil.get_abspath(file_path)
    #创建日志对象
    log = logging.getLogger(name)
    log.setLevel(level)
    fmt = format
    formatter = logging.Formatter(fmt)
    #创建控制台处理器
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    log.addHandler(handler)
    #如果日志目录不存在,则创建目录
    parent_dir = os.path.dirname(file_path)
    if not os.path.exists(parent_dir):
        os.makedirs(parent_dir, exist_ok=True)
    #创建文件日志处理器
    file_handler = handlers.RotatingFileHandler(file_path, encoding=file_encoding, maxBytes=file_maxBytes, backupCount=file_backup_count)
    file_handler.setFormatter(formatter)
    log.addHandler(file_handler)

    return log
Пример #2
0
import unittest

from common import CommonUtil
from common.ConfigUtil import YamlUtil
from BeautifulReport import BeautifulReport


# 获得配置
yaml_config = YamlUtil.get_yaml()
# 获得测试用例目录
testcase_dir = CommonUtil.get_value_by_navigate_from_dict(YamlUtil.get_yaml(), "testcase.dir")
testcase_dir = CommonUtil.get_abspath(testcase_dir)
loader = unittest.TestLoader().discover(testcase_dir)

reportDir = CommonUtil.get_value_by_navigate_from_dict(YamlUtil.get_yaml(), "testcase.reportDir")
reportDir = CommonUtil.get_abspath(reportDir)

br = BeautifulReport(loader)
br.report("desc", "beautifullReport.html", reportDir)


# with open(reportDir + "report.txt", "w") as f:
#     runner = unittest.TextTestRunner(f)
#     runner.run(loader)





Пример #3
0
import pymysql
from common.ConfigUtil import YamlUtil
from common import CommonUtil
from common.LoggerUtil import MyLog

log = MyLog.get_log()
_yaml_content = YamlUtil.get_yaml()
_host = CommonUtil.get_value_by_navigate_from_dict(_yaml_content, "mysql.host",
                                                   "localhost")
_port = CommonUtil.get_value_by_navigate_from_dict(_yaml_content, "mysql.port",
                                                   3306)
_user = CommonUtil.get_value_by_navigate_from_dict(_yaml_content, "mysql.user",
                                                   "root")
_password = str(
    CommonUtil.get_value_by_navigate_from_dict(_yaml_content, "mysql.password",
                                               "123456"))
_charset = CommonUtil.get_value_by_navigate_from_dict(_yaml_content,
                                                      "mysql.charset", "utf8")
_database = CommonUtil.get_value_by_navigate_from_dict(_yaml_content,
                                                       "mysql.database",
                                                       "utf8")
'''
注意:密码是字符串类型,charset设置为utf8(在mysql中utf8是utf-8的实现,两者是不同的)
游标读到的数据默认以tuple呈现,可以通过cursorclass=pymysql.cursors.DictCursor将返回值类型改为字典(其实是list<dict>)
'''


class HandleMysql:
    def __init__(self):
        try:
            self._conn = pymysql.connect(