def __init__(self, report_file, if_result_file=False): # 获取邮件配置 self._email = OperateConfig(constant.config_common_path) self._s_mtp = self._email.get_str('email', 's_mtp') self._port = self._email.get_str('email', 's_mtp_port') self._from_man = self._email.get_str('email', 'from') self._to_man = self._email.get_str('email', 'to') self._authorization_code = self._email.get_str('email', 'authorization_code') self._report_name = report_file self._result_file = if_result_file
def setUpClass(cls): cls.log.info('{}开始执行{}'.format('=' * 50, '=' * 50)) # 读取项目配置 cls.__pro_public = OperateConfig(config_pro_web) cls.homepage = cls.__pro_public.get_str('project', 'homepage') # 引用随机数据生成类 cls.faker = FakeData() # 引用关联参数读写类 cls.context = Context() # 创建生成器,返回一个迭代器,用于测试用例计数 cls._count_case = (x for x in range(1, 1000))
def __init__(self): # 引用日志类 self.__log = Logger('配置接口').get_logger() # 获取公共配置 self.__pro_public = OperateConfig(constant.config_pro_api) self.__address = self.__pro_public.get_str('project', 'address') self.__timeout = self.__pro_public.get_int('project', 'timeout') self.__proxy = self.__pro_public.get_str('project', 'proxy') # 接口信息 self._api_url = None self._headers = None self._params = None self._data = None self._cookies = None self._files = None self._timeout = self.__timeout self._proxies = self._set_proxies()
def __init__(self): # 引用日志类 self._log = Logger("MYSQL").get_logger() # 获取数据库配置 self._db_config = OperateConfig(config_common_path) try: self._conn = pymysql.connect( user=self._db_config.get_str('mysql', 'username'), password=self._db_config.get_str('mysql', 'password'), host=self._db_config.get_str('mysql', 'host'), port=self._db_config.get_str('mysql', 'port'), database=self._db_config.get_str('mysql', 'database')) self._log.info('成功连接数据库') except pymysql.Error as e: self._log.error('数据库连接失败:{}'.format(e))
def __init__(self): # 引用日志类 self._log = Logger("ORACLE").get_logger() # 获取数据库配置 self._db_config = OperateConfig(config_common_path) self._conn_str = '{}/{}@{}:{}/{}'.format( self._db_config.get_str('oracle', 'username'), self._db_config.get_str('oracle', 'password'), self._db_config.get_str('oracle', 'host'), self._db_config.get_str('oracle', 'port'), self._db_config.get_str('oracle', 'database')) try: self._conn = cx_Oracle.connect(self._conn_str) self._log.info('成功连接数据库') except cx_Oracle.Error as e: self._log.error('数据库连接失败:{}'.format(e))
def __init__(self, db_=0): # 引用日志类 self._log = Logger('REDIS').get_logger() # 获取redis配置信息 self._redis_conf = OperateConfig(config_common_path) try: pool = redis.ConnectionPool( host=self._redis_conf.get_str('redis', 'host'), port=self._redis_conf.get_str('redis', 'port'), password=self._redis_conf.get_str('redis', 'auth'), db=db_, decode_responses=True) self._conn = redis.StrictRedis(connection_pool=pool) self._log.info('成功连接REDIS,db({})'.format(db_)) except redis.exceptions.RedisError as e: self._log.error('REDIS连接失败:{}'.format(e))
def __init__(self): self._log = Logger('安卓引擎').get_logger() # 读取配置 self._reader = OperateConfig(constant.config_pro_app) self._if_wifi = self._reader.get_bool('server', 'if_wifi') self._android_mode = self._reader.get_str('server', 'android_mode')
paths.append(os.path.join(folder, file)) else: if file.endswith('.yaml'): paths.append(os.path.join(folder, file)) apis = [] for filename in paths: with open(filename) as fp: reader = fp.read() all_api = yaml.load(reader, Loader=yaml.FullLoader) for key, api in all_api.items(): if 'pytest' in key: apis.append((api.get('name'), api)) return apis kw = OperateConfig(constant.config_pro_api).get_str('project', 'filename_keyword') _all_api = read_pytest_apis(kw) logger = Logger('执行API测试').get_logger() @allure.title('{api_name}') @pytest.mark.parametrize('api_name,api', _all_api) # 调用全局fixture处理测试结果,每次全量测试时使用,调试时注释掉 @pytest.mark.usefixtures('bar') def test_main_api(api_name, api): """ pytest接口测试主入口 :param api_name: 接口名称 :param api: 接口信息 :return: None """
def __init__(self): # 引用日志类 self._log = Logger('浏览器引擎').get_logger() # 获取配置 self._reader = OperateConfig(constant.config_pro_web)