我想在 pytest-html 报告标题中指出 pytest 测试执行标记我正在尝试如下所示的方法。这没用。
conftest.py
#add test execution mark as a 'label' field to the report
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
pytest_html = item.config.pluginmanager.getplugin("html")
outcome = yield
report = outcome.get_result()
if item.config.getoption("-m"):
report.label = item.config.getoption("-m")
#add 'label' field to the title
def pytest_html_report_title(report):
mark = report.label if hasattr(report, "label") else ""
report.title = f"My Software: {mark} Test Report"