# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: basic_data.py @ide: PyCharm Community Edition @time: 2018-12-27 09:44 @blog: https://www.cnblogs.com/gotesting/ ''' import re from Common.read_config import ReadConfig # 获取配置文件中,正常用户名密码数据 class Context: rc = ReadConfig() normal_user = rc.get_config_str('basic','normal_user') normal_pwd = rc.get_config_str('basic','normal_pwd') class DoRegex: # 查找target中符合的数据并替换 @staticmethod def replace(target): pattern = '${(.*?)}' while re.search(pattern,target): m = re.search(pattern,target) key = m.group(1) from Common.basic_data import Context normal_user = getattr(Context,key) target = re.sub(pattern,normal_user,target,count=1) return target