from config import Conf import os from utils.YamlUtil import YamlReader import pytest from config.Conf import ConfigYaml from utils.RequestsUtil import Request #1、获取测试用例内容list #获取testlogin.yml文件路径 test_file = os.path.join(Conf.get_data_path(), "testlogin.yml") #print(test_file) #使用工具类来读取多个文档内容 data_list = YamlReader(test_file).data_all() print(data_list) #2、参数化执行测试用例 @pytest.mark.parametrize("login", data_list) def test_yaml(login): #初始化url,data url = ConfigYaml().get_conf_url() + login["url"] print("url %s" % url) data = login["data"] print("data %s" % data) #post请求 request = Request() res = request.post(url, json=data) #打印结果 print(res) if __name__ == "__main__":
import json import os import allure import pytest from common.handle_test import Handle from config import Conf from config.Conf import ConfigYaml from utils.Assert import Assertions from utils.YamlUtil import YamlReader getDataIndexValueTreeList = os.path.join(Conf.get_data_path(), "TITAN_16getDataIndexValueTreeList.yml") data_index_value_tree_list = YamlReader(getDataIndexValueTreeList).read_data_all() data_list = list() def get_data(second_data): a = list() if second_data["title"] is None or "title" not in second_data.keys(): title1 = " " else: title1 = second_data["title"] if "children" in second_data and second_data["children"]: for third_data in second_data["children"]: return get_data(third_data) else: a.append(title1) b = "--".join(a) return data_list.append(b) def get_indicator_data(response_data):
from config.Conf import ConfigYml from config import Conf import os from common.EXcelData import Data from utils.LogUtil import my_log from common import ExcelConfig from utils.RequestsUtil import Request import json import pytest from common import Base from utils.AssertUtil import AssertUtil import allure # 1、初始化信息 case_file = os.path.join(Conf.get_data_path(), ConfigYml().get_excel_file()) # 初始化测试用例文件 sheet_name = ConfigYml().get_excel_sheet() # 初始化测试用例sheet名称 # 获取运行测试用例列表 data_init = Data(case_file, sheet_name) run_list = data_init.get_run_data() log = my_log() # 日志 data_key = ExcelConfig.DataConfig # 初始化DataConfig # 2、测试用例方法,参数化运行 class TestExcel: def run_api(self, url, method, url_params, reference,
import allure import pytest from common import ExcelConfig, Base from common.ExcelData import Data from config import Conf from config.Conf import ConfigYaml # 1.初始化信息 # 1)初始化测试用例文件 from utils.AssertUtil import AssertUtil from utils.LogUtil import my_log from utils.RequestsUtil import Request case_file = os.path.join(Conf.get_data_path(), ConfigYaml().get_excel_file()) # 2)测试用例sheet名称 sheet_name = ConfigYaml().get_excel_sheet() # 3)获取运行测试用例列表 data_init = Data(case_file, sheet_name) run_list = data_init.get_run_data() # 4)日志 log = my_log() # 初始化dataconfig data_key = ExcelConfig.DataConfig # 2、测试用例方法,参数化运行 # 一个用例的执行 class TestExcel: # 1、增加Pyest
import json import os import allure import pytest from common.handle_test import Handle from config import Conf from config.Conf import ConfigYaml from utils.Assert import Assertions from utils.YamlUtil import YamlReader getDataIndexValueTreeList = os.path.join( Conf.get_data_path(), "TITAN_12getDataIndexValueTreeList.yml") data_index_value_tree_list = YamlReader( getDataIndexValueTreeList).read_data_all() def get_indicator_data(response_data): conf_indicator_list = ConfigYaml().get_titan_info() for indicator_name in conf_indicator_list: test_indicator_list = list() file = Conf.get_titan_indicator_path( ) + os.sep + indicator_name + ".txt" with open(file, "r", encoding="utf-8") as f: standard_indicator_list = eval(f.read()) for first_data in response_data: disease_title = first_data["title"] if disease_title == indicator_name: if "children" in first_data and first_data["children"]: for second_data in first_data["children"]: if second_data["title"] is None: second_data["title"] = " "
self.rlist = None # 3、yaml读取 # 单个及多个文档读取 def read_data(self): # 第一次调用data,读取yaml文档,如果不是,直接返回之前保存的数据 if not self._data: with open(self.yamlf, "r", encoding="utf-8") as f: self._data = yaml.safe_load(f) return self._data def read_data_all(self): if not self._data_all: with open(self.yamlf, "r", encoding="utf-8") as f: self._data_all = list(yaml.safe_load_all(f)) return self._data_all # 单个文档读取,返回列表 def read_list_data(self): self.data = self.read_data() self.rlist = [self.data] return self.rlist if __name__ == '__main__': get_patient_list = os.path.join(Conf.get_data_path(), "AKSO_getPatientList.yml") patient_list = YamlReader(get_patient_list).read_data_all() print(patient_list)