Advertisement

从0到1掌握自动化测试, pytest框架, hooks获取执行结果(23)

阅读量:

导读内容概览

    • 一、引言
      • 二、pytest_runtest_makereport
      • 三、实际操作示例
      • 四、初始化与清理过程
      • 五、初始化阶段出现的异常状况
      • 六、执行阶段发生的错误情形
      • 七、清理阶段存在的问题
      • 八、仅提取执行阶段的输出结果

一、前言

pytest所提供的诸多钩子(Hooks)函数,为测试用例框架的二次开发提供了便利条件,使我们能够依据具体需求对框架进行相应的调整与优化。首先应了解pytest_runtest_makereport这一钩子函数,通过深入学习该方法,可以更加明确地掌握测试用例的执行流程,并获取到各个测试用例的具体执行结果。

二、pytest_runtest_makereport

首先可以查阅相关的代码实现,在_pytest/runner.py文件中,导入该模块后,进入其中进行详细查看。

复制代码
    from _pytest import runner
    
    # 对应源码
    def pytest_runtest_makereport(item, call):
    """ return a :py:class:`_pytest.runner.TestReport` object
    for the give

全部评论 (0)

还没有任何评论哟~