def __init__(self): #获取配置文件里面的MySQL配置 config = Reading(http_path.config_path_control) host = config.get('MYSQL', 'Host_name') port = config.get_int('MYSQL', 'port') #port是一个数字,使用getint user = config.get('MYSQL', 'user') pwd = config.get('MYSQL', 'pwd') try: self.mysql = pymysql.connect( host=host, user=user, password=pwd, database='future', port=port, cursorclass=pymysql.cursors.DictCursor) #cursorclass=pymysql.cursors.DictCursor 返回字典格式 except BaseException as e: print("数据库链接异常:{}".format(e)) raise e
from common import http_path from common.Http_config import Reading import logging import time import os import HTMLTestRunnerNew from logging.handlers import TimedRotatingFileHandler #根据时间进行滚动 from logging.handlers import RotatingFileHandler #根据文件大小进行滚动 my_log = logging.getLogger( Reading(http_path.config_path_control).get('LOG', 'logger_name')) my_log.setLevel(Reading(http_path.config_path_control).get('LOG', 'log_level')) leve = Reading(http_path.config_path_control) fmt = " %(asctime)s %(levelname)s %(filename)s %(funcName)s [ line:%(lineno)d ] %(message)s" #%%(asctime)s-%%(levelname)s-%%(filename)s-%%(funcName)-s[line:%%(lineno)d]-%%(name)s fmt1 = leve.get('LOG', 'formatter') datefmt = '%a, %d %b %Y %H:%M:%S' Console = logging.StreamHandler() #格式Fri, 03 Aug 2018 17:02:05 周几+日期+月份+年份+时+分+秒 curTime = time.strftime('%Y-%m-%d', time.localtime(time.time())) def get_log_dir(): # 获取当天的日志存放目录 log = os.path.join(http_path.log_path, curTime) #基本路径+当天时间 if not os.path.isdir(log): #判断是否有当天时间的日志目录 os.makedirs(log) #没有新建一个目录 return log info_file = os.path.join(get_log_dir(), 'info.log') #最终日志路径 error_file = os.path.join(get_log_dir(), 'error.log')
from common.http_reading_excel_01 import DoExcel from common import http_path from common.Http_config import Reading from common.http_log import HttpLog from common.regular_expression import Regular from common.basic_data import Context from common.mysql import MysqlUtill import unittest import json from common.common_user import Login #创建日志对象,装载日志 my_log = HttpLog() #创建取配置对象 con = Reading(http_path.config_path_control) #获取需要的执行的测试用例ID config = con.get('CASE','button') #读取配置文件里面的URL地址 config_url = con.get('URL','url_date') #读取测试数据,实例化测试数据对象 excel_date = DoExcel(http_path.case_path,config) #充值 excel_date_recharge = excel_date.get_case('recharge2') @ddt class HttpCase(Login): #class HttpCase(unittest.TestCase): @classmethod def setUpClass(cls): Login().test_login() #固定投资用户登录 def setUp(self): self.sql = con.get('SQL', 'Income_LeaveAmount')