httprunner3.x源码阅读

-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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值