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


 

# -*- 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)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM