看起来你使用的是像pytest-html这样的插件。 如果是这种情况检查该插件的文档提供了所有的钩子。
为pytest-HTML下面是提供的钩子 您可以添加从夹具修改request.config._html.environment
改变报告的环境部分:
@pytest.fixture(autouse=True)
def _environment(request):
request.config._environment.append(('foo', 'bar'))
您可以通过创建一个“额外的细节添加到HTML报告'报告对象列表。下面的示例将不同类型的使用pytest_runtest_makereport
钩群众演员,可以在一个插件或conftest.py
文件来实现:
import pytest
@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':
# always add url to report
extra.append(pytest_html.extras.url('http://www.example.com/'))
xfail = hasattr(report, 'wasxfail')
if (report.skipped and xfail) or (report.failed and not xfail):
# only add additional html on failure
extra.append(pytest_html.extras.html('<div>Additional HTML</div>'))
report.extra = extra
你使用pytest-html插件吗? –