pytest钩子函数--pytest_runtest_makereport获取结果

1、在项目根目录添加config.py

2、from _pytest import runner======》pytest_runtest_makereport

3、item 是测试用例,call是测试步骤

import pytest
#钩子函数
@pytest.hookimpl(hookwrapper=True,tryfirst=True)
def pytest_runtest_makereport(item,call):
    out =yield
    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))
    if report.when=='call':
        print("call通过")

4、测试案例

@pytest.mark.parametrize("data", [("zhangsan")])
def test_08(self,data):
        print(data)

5、执行结果

 6、执行过程分为3个阶段

setup--call--teardown

posted @ 2021-10-29 10:14  呆呆蒙蒙  阅读(220)  评论(0编辑  收藏  举报