使用conftest.py
钩子可以捕获test case name
及其status
,但是可以使用error message
捕获pytest_runtest_protocol
我从pytest文档中找到了以下代码段:
def pytest_runtest_protocol(item, log=True, nextitem=None):
# Provide's test case execution details
reports = runtestprotocol(item, nextitem=nextitem)
for report in reports:
if report.when == 'call':
print('\n%s --- %s' % (item.name, report.outcome))
return True
文档中提到pytest_runtest_protocol
也包含异常详细信息
答案 0 :(得分:0)
发现经过两次搜索后,我们无法使用pytest_runtest_protocol()
收到错误消息:
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
outcome = yield
rep = outcome.get_result()
if rep.when == "call" and rep.failed:
# Error message if failed
print(rep.longreprtext)
记录了我对其他人的更改here