我使用pytesthtml插件为我的测试用例生成报告。如果脚本失败,我想添加一个行项目。这是我的密码——
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行项目。在
还有一种方法可以让我在脚本之间添加这样的行项目到报表中。在
非常感谢你的帮助。在
这应该是有效的:
相关问题 更多 >
编程相关推荐