通用“runtest”挂钩 http://doc.pytest.org/en/latest/writing_plugins.html#_pytest.hookspec.pytest_runtest_protocol
所有与 runtest 相关的钩子都会接收一个 pytest.Item 对象。
pytest_runtest_protocol(item, nextitem)[来源]
implements the runtest_setup/call/teardown protocol for the given test item, including capturing exceptions and calling reporting hooks.
Parameters:
item – test item for which the runtest protocol is performed.
nextitem – the scheduled-to-be-next test item (or None if this is the end my friend). This argument is passed on to pytest_runtest_teardown().
Return boolean:
True if no further hook implementations should be invoked.
pytest_runtest_setup(项目)[来源]
called before pytest_runtest_call(item).
pytest_runtest_call(项目)[来源]
called to execute the test item.
pytest_runtest_teardown(item, nextitem)[来源]
called after pytest_runtest_call.
Parameters: nextitem – the scheduled-to-be-next test item (None if no further test item is scheduled). This argument can be used to perform exact teardowns, i.e. calling just enough finalizers so that nextitem only needs to call setup-functions.
pytest_runtest_makereport(项目,调用)[来源]
return a _pytest.runner.TestReport object for the given pytest.Item and _pytest.runner.CallInfo.
为了更深入地理解,您可以在 _pytest.runner 中查看这些钩子的默认实现,也可以在 _pytest.pdb 中查看这些钩子的默认实现,它与 _pytest.capture 及其输入/输出捕获交互,以便在发生测试失败时立即进入交互式调试。
报告的 _pytest.terminal 特别使用报告挂钩来打印有关测试运行的信息。