我在通过pytest进行的每个测试中都创建了png图像,并且我也在使用pytest-html创建pytest报告。问题是,我不知道如何将这些png图像添加到pytest报告中。
我知道我可以在conftest.py中创建一个钩子,但是我不知道如何使用它并对其进行配置。我不了解“ item”和“ call”变量,而且我不确定如何链接png文件。
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item,call):
pytest_html = item.config.pluginmanager.getplugin('html')
outcome = yield
report = outcome.get_result()
extra = getattr(report,'extra',[])
if report.when == 'call':
extra.png(image)
report.extra = extra