[英]Pytest-html Customization
I am using pytest-html plugin for report generation for my test cases. 我正在使用pytest-html插件为我的测试用例生成报告。 I want to add a line item if the script fails. 如果脚本失败,我想添加一个订单项。 So here's my code--- 所以这是我的代码
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
I can see the report getting generatesd but it doesnt have a line item as Additional HTML. 我可以看到报告正在生成,但是它没有作为其他HTML的订单项。
Also is there a way via which I can add such line items in between of my scripts to the report. 还可以通过一种方法将我的脚本之间的此类订单项添加到报告中。
Really appreciate help. 真的很感谢帮助。
This should work: 这应该工作:
@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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.