def init_db(db_alias): db_info = Conf.ConfigYaml().get_db_config_info(db_alias) # 2、初始化数据库信息,通过配置 host = db_info["db_host"] user = db_info["db_user"] password = db_info["db_password"] name = db_info["db_name"] charset = db_info["db_charset"] port = int(db_info["db_port"]) # 3、初始化mysql对象 conn = Mysql(host, user, password, name, charset, port) # print(conn) return conn
def setup_class(self): global run_list, run_case self.data = DataConfig() self.asserte = AssertUtil() self.request = Request() self.log = my_log() case_name = Conf.get_excel_file() case_sheet = Conf.ConfigYaml().get_case_sheet() case_init = Data(case_name, case_sheet) run_list = case_init.get_case_list() run_case = case_init.get_run_data() data = run_list[0][self.data.params] res = self.request.post(data=data) # print(res) self.token = res["data"]["token"] self.uid = res["data"]["uid"] self.sessionkey = res["data"]["session_key"]
import json import os import allure import pytest import common.Constant as Const from common import ExcelConfig, Base, ExcelData from config import Conf from utils.AssertUtil import AssertUtil from utils.LogUtil import my_log # 获取待执行用例的数据列表 case_file = os.path.join(Conf.get_data_path(), Conf.ConfigYaml().get_excel_file()) sheet_name = Conf.ConfigYaml().get_excel_sheet() Data_init = ExcelData.Data(case_file, sheet_name) run_list = Data_init.get_run_data() # log初始化并开始记录执行内容 log = my_log(__file__.split("/")[-1]) sheet_name_keys = str(list(sheet_name.keys())) log.info("\n\n\n\n=====测试用例Excel文件:%s=====" "\n=====执行sheet_name:%s=====" "\n=====sheet表中共%s条用例需执行=====\n" % (case_file, sheet_name_keys, str(len(run_list))) + "=" * 96) setattr(Const.GetConst, "EXEC_MODULAR", sheet_name_keys) # 获取预设好的参数,便于全局使用 data_key = ExcelConfig.DataConfig global_params = Conf.ConfigYaml().get_global_params()
self.log.error("Mysql 执行失败") self.log.error(ex) return False return True # 4、关闭对象 def __del__(self): if self.cursor is not None: self.cursor.close() if self.conn is not None: self.conn.close() if __name__ == "__main__": db_info = Conf.ConfigYaml().get_db_config_info("db_1") # 2、初始化数据库信息,通过配置 host = db_info["db_host"] user = db_info["db_user"] password = db_info["db_password"] name = db_info["db_name"] charset = db_info["db_charset"] port = int(db_info["db_port"]) # 3、初始化mysql对象 mysql = Mysql(host, user, password, name, charset, port) re = mysql.exec("update goods set name ='Chinese' where id =1") r = mysql.fetchone("select * from goods") print(re) print(r)