获取 pytest 执行结果 在 conftest 中添加以下方法
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
"""将用例结果插入到DB"""
# 用例执行结果 out
outcome = yield
# 从钩子方法的调用结果中获取测试报告 rep
report = outcome.get_result()
# rep.when call 步骤结果 setup:用例结果 teardown
print('测试报告:%s' % report)
print('步骤:%s' % report.when)
if report.when == "setup":
print("用例方法")
# 测试方法
print('nodeid:%s' % report.nodeid)
# 用例描述 就是方法注释
print('description:%s' % str(item.function.__doc__))
# passed or failed
print(('运行结果: %s' % report.outcome))