python - 接口自动化测试 - ReadConfig - 读取配置文件封装

python - 接口自动化测试 - ReadConfig - 读取配置文件封装_第1张图片python - 接口自动化测试 - ReadConfig - 读取配置文件封装_第2张图片python - 接口自动化测试 - ReadConfig - 读取配置文件封装_第3张图片

 

# -*- coding:utf-8 -*-

'''
@project: ApiAutoTest
@author: Jimmy
@file: read_config.py
@ide: PyCharm Community Edition
@time: 2018-12-21 13:53
@blog: https://www.cnblogs.com/gotesting/

'''


import configparser
import os
from Common import contants

# 创建实例
# 加载配置文件
# 根据section option获取值


class ReadConfig:

    # 初始化函数:实例化conf对象,读取传入的配置文件
    def __init__(self):
        self.conf = configparser.ConfigParser()
        file = os.path.join(contants.conf_dir,'global.conf')
        self.conf.read(file)
        if self.get_config_boolean('switch','button'):
            test_conf = os.path.join(contants.conf_dir,'test_env.conf')
            self.conf.read(test_conf)
        else:
            online_conf = os.path.join(contants.conf_dir,'online_env.conf')
            self.conf.read(online_conf)

    def get_config_str(self,section,option):
        return self.conf.get(section,option)

    def get_config_boolean(self,section,option):
        return self.conf.getboolean(section,option)

    def get_config_int(self,section,option):
        return self.conf.getint(section,option)

    def get_config_float(self,section,option):
        return self.conf.getfloat(section,option)

 

转载于:https://www.cnblogs.com/gotesting/p/10156139.html

你可能感兴趣的:(python - 接口自动化测试 - ReadConfig - 读取配置文件封装)