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