Hook 方法之 pytest_runtest_makereport:
@hookspec(firstresult=True)
def pytest_runtest_makereport(item, call):
""" return a :py:class:`_pytest.runner.TestReport` object
for the given :py:class:`pytest.Item <_pytest.main.Item>` and
:py:class:`_pytest.runner.CallInfo`.
Stops at first non-None result, see :ref:`firstresult` """
官方的不太懂,根据自己使用后的理解(不一定精准),这个钩子方法的大概作用是:
对于给定的测试用例(item)和调用步骤(call),返回一个测试报告对象(_pytest.runner.TestReport);具体表现为:这个钩子方法会被每个测试用例调用 3 次,分别是:
- 用例的 setup 执行完毕后,调用 1 次,返回 setup 的执行结果;
- 用例执行完毕之后,调用 1 次,返回测试用例的执行结果;
- 用例的 teardown 执行完毕后,调用1 次,返回 teardown 的执行结果;
获取测试用例的执行结果:
准备测试用例:
class TestDemoA:
def test_A_001(self):

最低0.47元/天 解锁文章
1651





