-loader.py
核心代码:
将载入的yaml/json文件转化为字典,字典转化为testcase对象
def load_testcase_file(testcase_file: Text) -> TestCase:
"""load testcase file and validate with pydantic model"""
testcase_content = load_test_file(testcase_file)
testcase_obj = load_testcase(testcase_content)
testcase_obj.config.path = testcase_file
return testcase_obj
将载入的.env中的环境变量输出为字典
def load_dot_env_file(dot_env_path: Text) -> Dict:
将载入的csv文件中定义数据输出为字典列表 用于参数化测试数据
def load_csv_file(csv_file: Text) -> List[Dict]:
输出文件夹下所有yml/.yaml/.json/_test.py列表
def load_folder_files(folder_path: Text, recursive: bool = True) -> List:
载入模块的所有方法,返回方法字典
def load_module_functions(module) -> Dict[Text, Callable]:
""" load python module functions.
Args:
module: python module
Returns:
dict: functions mapping for specified python module
{
"func1_name": func1,
"func2_name": func2
}
"""
搜索某文件 返回绝对路径 递归不断向上查找直到根目录
def locate_file(start_path: Text, file_name: Text) -> Text:
定位debugtalk.py的位置,该文件作为httprunner项目的锚点,相对路径依据于此
def locate_debugtalk_py(start_path: Text) -> Text:
载入debugtalk中的function ,载入模型,载入模型中的function
def load_debugtalk_functions() -> Dict[Text, Callable]:
从testpath中载入项目相关的test case/.env/debugtalk.py
def load_project_meta(test_path: Text, reload: bool = False) -> ProjectMeta:
将绝对路径改为相对路径
def convert_relative_project_root_dir(abs_path: Text) -> Text:
-make.py 主要用来讲yaml/json文件转化为pytest
核心代码
make_testcase(testcase: Dict, dir_path: Text = None) -> Text:
"""将testcase字典转化为pytest文件"""
# ensure compatibility with testcase format v2
testcase = ensure_testcase_v3(testcase)
# validate testcase format
load_testcase(testcase)
testcase_abs_path = __ensure_absolute(testcase["config"]["path"])
logger.info(f"start to make testcase: {testcase_abs_path}")
testcase_python_abs_path, testcase_cls_name = convert_testcase_path(
testcase_abs_path
)
if dir_path:
testcase_python_abs_path = os.path.join(
dir_path, os.path.basename(testcase_python_abs_path)
)
global pytest_files_made_cache_mapping
if testcase_python_abs_path in pytest_files_made_cache_mapping:
retur