编辑:由于我需要访问测试项目的funcargs(和测试结果)以便我的报告,我能够将逻辑移动到pytest_runtest_makereport(item,__ multicall__)钩子.诀窍是执行multiicall,它返回报表对象:
@pytest.mark.tryfirst
def pytest_runtest_makereport(item, call, __multicall__):
report = __multicall__.execute()
# then I was able to manipulate report and get the same results as below
Bruno的回答给了我更多彻底分析这个功能所需的动力:)
所以这是它的工作原理:
def pytest_runtest_logreport(report):
if report.failed:
report.longrepr.sections.append(("Header", "Message", "-"))
report.sections.append(("Captured stdout", "This is added to stdout"))
report.sections.append(("Captured stderr", "This is added to stderr"))
report.sections.append(("Custom Section", "This can only be seen in the console - the xml won't have it."))
longrepr属性仅在出现故障时可用.它需要一个3元组,最