首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pytest-html:基于标记自定义报表标题

Pytest-html:基于标记自定义报表标题
EN

Stack Overflow用户
提问于 2021-06-22 13:31:55
回答 1查看 525关注 0票数 2

我想在pytest-html报告标题中指明pytest测试执行标记,我正在尝试如下所示的方法。它不起作用。

conftest.py

代码语言:javascript
复制
#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"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-26 05:44:05

通过在pytest_configure钩子中将label作为一个属性添加到pytest中,解决了这个问题:

代码语言:javascript
复制
#add test execution mark as a 'label' field to the pytest namespace
def pytest_configure(config):
    pytest.label = config.getoption("-m")

#add 'label' field to the title
def pytest_html_report_title(report):
    report.title = f"My Software: {pytest.label} Test Report"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68084501

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档