工具类里放read_config.py方便以后调用
1 import configparser 2 3 4 class ReadConfig: 5 # 参数化 6 def read_config(self, filename, sections, button): 7 cf = configparser.ConfigParser() 8 cf.read(filename, encoding="utf-8") 9 return cf.get(sections, button) 10 11 12 if __name__ == '__main__': 13 res = ReadConfig().read_config("case.config", "BUTTON", "button") 14 print(res)
在do_excel文件修改
def get_data(self): wb = load_workbook(self.file_name) sheet = wb[self.sheet_name] test_data = [] button = ReadConfig().read_config("case.config", "BUTTON", "button") for i in range(2, sheet.max_row+1): sub_data = {} sub_data['case_id'] = sheet.cell(i, 1).value sub_data['module'] = sheet.cell(i, 2).value sub_data['title'] = sheet.cell(i, 3).value sub_data['method'] = sheet.cell(i, 4).value sub_data['url'] = sheet.cell(i, 5).value sub_data['data'] = sheet.cell(i, 6).value sub_data['expected'] = sheet.cell(i, 7).value test_data.append(sub_data) # 存储了所有的数据 final_data = [] if button == "all": final_data = test_data else: for item in test_data: if item['case_id'] in eval(button): # 记得这里进行数据类型转换 final_data.append(item) return final_data
主要注意数据类型转换
不用传参的方式,而是定义一个变量接收值
button = ReadConfig().read_config("case.config", "BUTTON", "button")