7-7接口自动化测试框架设计开发之模型搭建--运用配置文件处理请求数据
本章只用到了server.ini和handle_init.py,实现到效果是,获取server.ini中的值
server.ini [server] host=http://www.imooc.com username=哈哈 password=1111 is_run=3
handle_init.py
#coding=utf-8 import sys import os import openpyxl import configparser base_path = "/Users/jiangjuanjuan/Downloads/itemA/Config/server.ini" class HandleInit: def load_init(self): cf = configparser.ConfigParser() cf.read(base_path,encoding='utf-8-sig') return cf def get_value(self,key,section=None): ''' 获取ini里面的value ''' if section == None: section = 'server' try: cf = self.load_init() data = cf.get(section, key) except Exception: print("没有获取到值") data = None return data if __name__ == '__main__': hi = HandleInit() print(hi.get_value("username"))