Pytest-钩子函数获取用例执行结果
获取测试用例的运行结果:
#conftest.py import pytest @pytest.hookimpl(hookwrapper=True, tryfirst=True) def pytest_runtest_makereport(item, call): print('------------------------------------') # 获取钩子方法的调用结果 out = yield print('用例执行结果', out) # 3. 从钩子方法的调用结果中获取测试报告 report = out.get_result() print('测试报告:%s' % report) print('步骤:%s' % report.when) print('nodeid:%s' % report.nodeid) print('description:%s' % str(item.function.__doc__)) print(('运行结果: %s' % report.outcome))
#执行用例,在控制台可查看结果: ------------------------------------ 用例执行结果 <pluggy.callers._Result object at 0x00000257F14DF048> 测试报告:<TestReport 'testcases/goods_demo/test_v1_goods.py::TestGoods::test_v1_goods[goods_data1]' when='call' outcome='passed'> 步骤:call nodeid:testcases/goods_demo/test_v1_goods.py::TestGoods::test_v1_goods[goods_data1] description:查询商品 运行结果: passed

浙公网安备 33010602011771号