首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pytest-html定制

Pytest-html定制
EN

Stack Overflow用户
提问于 2017-06-01 20:17:22
回答 1查看 1.4K关注 0票数 2

我使用pytest-html插件为我的测试用例生成报告。如果脚本失败,我想添加一个行项目。所以这是我的代码

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

def test_sayHello():

        assert False, "I mean for this to fail"
        print "hello"


def test_sayBye():
        print "Bye"


I am running the scipt using -
 pytest --html=report.html

我可以看到报告正在生成,但它没有作为附加HTML的行项目。

还有一种方法可以让我在我的脚本之间添加行项目到报告中。

非常感谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2017-07-30 04:56:44

这应该是可行的:

代码语言:javascript
复制
@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.append(pytest_html.extras.html('<p>some html</p>'))
        report.extra = extra
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44307345

复制
相关文章

相似问题

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