def __init__(self, ip='', username='', password=''): self.__username = username self.__password = password self.__sys_ip = ip self.__log = Log.MyLog() self.__config = parse_config.ConfigUtil("DEFAULT") self.__log_level = self.__config.get_log_level()
def __init__(self, remote_ip='', username='', password=''): self.__config = ConfigUtil() if not remote_ip: print('远程机器的IP信息缺失!') raise Exception('远程机器的IP信息缺失!') if username: self.__username = username else: self.__username = self.__config.get_authority_user() if password: self.__password = password else: self.__password = self.__config.get_authority_pwd() self.__remote_ip = remote_ip self.__linux = Shell(ip=self.__remote_ip, username=self.__username, password=self.__password) self.__ssh = self.__linux.get_ssh() self.__sftp = self.__ssh.open_sftp() self.__log = Log.MyLog() self.__localMachine = LocalHost() self.__work_folder = self.__localMachine.Dir.get_work_folder() if not os.path.exists(self.__work_folder): os.mkdir(self.__work_folder)
def __init__(self, test_env=None): self.__env = test_env if test_env else "DEFAULT" self.__config = ConfigUtil(self.__env) self.__namespace = self.__config.get_pod_namespace() self.__linux = Shell(self.__config.get_main_server_ip(), self.__config.get_authority_user(), self.__config.get_authority_pwd()) self.__log = Log.MyLog()
def copy_file(self, old_file, new_file): log = Log.MyLog() with open(old_file, "r", encoding="utf-8") as f1, open(new_file, "w", encoding="utf-8") as f2: for line in f1: f2.write(line) log.info('复制文件{0}内容完成,生成新的文件{1}'.format(old_file, new_file))
def modify_and_create_file(self, old_file, new_file, update_content): log = Log.MyLog() with open(old_file, "r", encoding="utf-8") as f1, open(new_file, "w", encoding="utf-8") as f2: for line in f1: for (k, v) in update_content.items(): if k in line: line = line.replace(k, v) f2.write(line) log.info('修改文件{0}内容完成,生成新的文件{1}'.format(old_file, new_file))
def modify_file(self, file, update_content): log = Log.MyLog() file_data = "" with open(file, "r", encoding="utf-8") as f: for line in f: for (k, v) in update_content.items(): if k in line: line = line.replace(k, v) file_data += line with open(file, "w", encoding="utf-8") as f: f.write(file_data) log.info('修改文件{0}内容完成'.format(file))
def get_test_config_folder(self): log = Log.MyLog() test_config_path = os.path.abspath( os.path.dirname(__file__)).split('/common')[0] + "/test/config/" if not os.path.exists(test_config_path): log.error('获取本地test config路径失败!') return None log.info('成功获取本地路径:test config={0}'.format(test_config_path)) return test_config_path
def get_conf_folder(self): log = Log.MyLog() conf_path = os.path.abspath( os.path.dirname(__file__)).split('/common')[0] + "/conf/" if not os.path.exists(conf_path): log.error('获取本地conf路径失败!') return None log.info('成功获取本地路径:conf={0}'.format(conf_path)) return conf_path
def delete_file_in_folder(self, file_path): log = Log.MyLog() if os.path.exists(file_path): for fileList in os.walk(file_path): for name in fileList[2]: os.chmod(os.path.join(fileList[0], name), stat.S_IWRITE) os.remove(os.path.join(fileList[0], name)) shutil.rmtree(file_path) log.info('成功删除本地文件夹{0}下的文件'.format(file_path)) return True else: log.warning('删除本地文件夹{0}下的文件失败!'.format(file_path)) return False
def get_work_folder(self): log = Log.MyLog() worker_folder_path = os.path.abspath( os.path.dirname(__file__)).split('/common')[0] + "/work_folder/" if not os.path.exists(worker_folder_path): try: os.mkdir(worker_folder_path) except Exception as e: log.error('获取本地work folder路径失败!失败原因:{0}'.format(e)) return None log.info('成功获取本地路径:work folder={0}'.format(worker_folder_path)) return worker_folder_path
def __init__(self): """ 初始化 """ self.config = ConfigParser() self.log = Log.MyLog() self.conf_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'environment.ini') if not os.path.exists(self.conf_path): raise FileNotFoundError("请确保配置文件存在!") self.config.read(self.conf_path, encoding='utf-8') self.host_teacher = self.get_conf(Config.TITLE_TEACHER, Config.VALUE_HOST) self.host_parent = self.get_conf(Config.TITLE_PARENT, Config.VALUE_HOST)
def replace_line_with_new_str(self, file, key, new_str): try: log = Log.MyLog() with open(file, 'r', encoding='utf-8') as f: lines = [] # 创建了一个空列表,里面没有元素 for line in f.readlines(): if line != '\n': lines.append(line) f.close() with open(file, 'w', encoding='utf-8') as f: for line in lines: if key in line: line = new_str f.write('%s\n' % line) else: f.write('%s' % line) log.info('替换文件{0}下包含关键字符{1}的行内容成功'.format(file, key)) except Exception as e: log.error('替换文件{0}下包含关键字符{1}的行内容失败!异常信息:{2}'.format( file, key, str(e)))
def __init__(self, remote_ip='', username='', password=''): self.__config = ConfigUtil() if not remote_ip: print('远程机器的IP信息缺失!') raise Exception('远程机器的IP信息缺失!') if username: self.__username = username else: self.__username = self.__config.get_authority_user() if password: self.__password = password else: self.__password = self.__config.get_authority_pwd() self.__remote_ip = remote_ip self.__linux = Shell(ip=self.__remote_ip, username=self.__username, password=self.__password) self.__log = Log.MyLog()
def __init__(self, test_env='P1-K8S-ENV', db_type='db'): self.__test_env = test_env self.__config = parse_config.ConfigUtil(self.__test_env) self.__log_config = parse_config.ConfigUtil("LOG") self.__driver = self.__config.get_driver() if db_type != 'db': self.__url = self.__config.get_meta_db_jdbc_url() else: self.__url = self.__config.get_db_jdbc_url() self.__user = self.__config.get_db_user() self.__password = self.__config.get_db_pwd() self.__jar = self.__config.get_ldb_driver_file() self.__conn = jaydebeapi.connect( self.__driver, self.__url, [self.__user, self.__password], self.__jar, ) self.__curs = self.__conn.cursor() self.__log = Log.MyLog()
import os import common.HTMLTestRunner as HTMLTestRunner import getpathInfo import unittest import readConfig import common.Log from common.emailDemo import sendReport from common.configEmail import Email from common import Log # send_mail = sendReport().send_email() path = getpathInfo.MakePath().get_Path() # on_off = readConfig.ReadConfig().get_email('on_off') log = Log.MyLog().get_log().get_logger() # resultPath = getpathInfo.set_reportPath() class AllTest: #定义一个类AllTest def __init__(self): #初始化一些参数和数据 global resultPath #resultPath = os.path.join(report_path, "report.html")#result/report.html # resultPath = getpathInfo.MakePath().get_resultpath('result') resultPath = getpathInfo.MakePath().set_reportPath( 'result', getpathInfo.nowTime + '.html') self.caseListFile = os.path.join(path, "caselist.txt") #配置执行哪些测试文件的配置文件路径 self.caseFile = os.path.join(path, "testCase") #真正的测试断言文件路径 self.caseList = [] log.info('resultPath' + resultPath) #将resultPath的值输入到日志,方便定位查看问题 log.info('caseListFile' + self.caseListFile) #同理 log.info('caseList' + str(self.caseList)) #同理
author:xiaoma datetime:2019/12/24 14:35 describe: """ import allure import pytest from params.parent_param_read_yaml import Login from config.config import Config from base.request_method import RequestMethod from common.Assert import Assertions from common.header import HeaderUtil from common import Log log = Log.MyLog() @allure.feature("家长端登录") class TestLogin: @allure.title("正确的账号登录") def test_login_01(self): log.info("正确的账号登录") conf = Config() data = Login().yaml_data urls = data.url params = data.data headers = data.header api_url = conf.host_parent + urls[0]
def __init__(self): self.log = Log.MyLog()