def setUpClass(cls): cls.WS = WebService() cls.con = DoMysql("dbName1") cls.cf = DoConf(constant.globe_conf_dir) cls.log = LogTools(__name__) cls.log.mylog.info("开始测试") setattr(context.Context, "user_id", context.create_name())
def setUpClass(cls): cls.WS = WebService() cls.sql = DoMysql("dbName1") cls.cf = DoConf(constant.globe_conf_dir) cls.log = LogTools(__name__) cls.log.mylog.info("开始测试") setattr(context.Context, "cre_id", IdNumber.generate_id(random.randint(0, 1)))
def __init__(self): conf = DoConf(constant.globe_conf_dir) # 打开数据库连接 self.db = pymysql.Connection(conf.get_value('dev_db', 'host'), conf.get_value('dev_db', 'username'), conf.get_value('dev_db', 'pwd'), conf.get_value('dev_db', 'dbName'), cursorclass=pymysql.cursors.DictCursor) #将游标执行的结果以字典返回 # 使用 cursor() 方法创建一个游标对象 cursor self.cursor = self.db.cursor()
def param_replace(data): p = "#(.*?)#" while re.search(p, data): params = re.search(p, data) params1 = params.group(1) try: params2 = DoConf(constant.globe_conf_dir).get_value('data', params1) except configparser.NoOptionError as e: if hasattr(Context, params1): params2 = getattr(Context, params1) else: print("找不到相关值") raise e data = re.sub(p, params2, data, count=1) return data
class WebService: log = LogTools(__name__) cf = DoConf(constant.globe_conf_dir) def web_services(self, url, params, method): url = "http://" + self.cf.get_value("dev_info", "domain_name") + ":" + self.cf.get_value("dev_info", "port") + url self.log.mylog.debug("测试地址是{}".format(url)) self.log.mylog.debug("测试参数是{}".format(params)) if type(params) is str: params = eval(params) client = Client(url) try: result = eval("client.service.{0}({1})".format(method, params)) self.log.mylog.debug("响应信息是{}".format(result)) msg = result.retInfo except WebFault as e: msg = e.fault.faultstring warnings.simplefilter('ignore', ResourceWarning) self.log.mylog.debug("响应信息是{}".format(e)) return msg
def __init__(self, log_name): conf = DoConf(constant.globe_conf_dir) # 定义一个日志收集器 self.mylog = logging.getLogger(log_name) # 设置收集级别 self.mylog.setLevel(conf.get_value('log_level', 'debug')) # 设置日志输出格式 famatter = logging.Formatter(conf.get_value('log_format', 'format')) # 设置日志控制台输出 hdr = logging.StreamHandler() hdr.setLevel(conf.get_value('log_level', 'debug')) hdr.setFormatter(famatter) # 设置日志文件输出 fdr = logging.FileHandler(os.path.join(constant.log_dir, 'log_info.log'), encoding='utf-8') fdr.setLevel(conf.get_value('log_level', 'debug')) fdr.setFormatter(famatter) # 收集渠道与日志收集器 self.mylog.addHandler(hdr) self.mylog.addHandler(fdr)
def setUpClass(cls): cls.resp = Request() cls.con = DoMysql() cls.conf = DoConf(constant.globe_conf_dir) cls.log = LogTools(__name__)
def setUpClass(cls): cls.resp = Request() cls.conf = DoConf(constant.globe_conf_dir) cls.con = DoMysql()
def setUpClass(cls): cls.WS = WebService() cls.cf = DoConf(constant.globe_conf_dir) cls.log = LogTools(__name__) cls.log.mylog.info("开始测试")