创建使用PYTEST中失败测试的错误消息创建JIRA票证
我有一个代码生成报告并在测试失败时添加屏幕截图:
def pytest_runtest_makereport(item):
pytest_html = item.config.pluginmanager.getplugin('html')
outcome = yield
report = outcome.get_result()
extra = getattr(report, 'extra', [])
if report.when == 'call' or report.when == "setup":
xfail = hasattr(report, 'wasxfail')
if (report.skipped and xfail) or (report.failed and not xfail):
file_name = report.nodeid.replace("::", "_") + ".png"
_capture_screenshot(file_name)
if file_name:
create_jira_issue(report.captlog, file_name)
html = '<div><img src="%s" alt="screenshot" style="width:304px;height:228px;" ' \
'onclick="window.open(this.src)" align="right"/></div>' % file_name
extra.append(pytest_html.extras.html(html))
report.extra = extra
它还创建了带有描述和屏幕截图的JIRA票证。我想将其作为“描述”基本上是日志(我已经拥有的)以及断言失败信息。
有没有办法在此处获取信息并通过它?
也许有一种更好的方法来创建失败测试的门票吗?
I have a piece of code that generates a report and adds a screenshot to it when test fails:
def pytest_runtest_makereport(item):
pytest_html = item.config.pluginmanager.getplugin('html')
outcome = yield
report = outcome.get_result()
extra = getattr(report, 'extra', [])
if report.when == 'call' or report.when == "setup":
xfail = hasattr(report, 'wasxfail')
if (report.skipped and xfail) or (report.failed and not xfail):
file_name = report.nodeid.replace("::", "_") + ".png"
_capture_screenshot(file_name)
if file_name:
create_jira_issue(report.captlog, file_name)
html = '<div><img src="%s" alt="screenshot" style="width:304px;height:228px;" ' \
'onclick="window.open(this.src)" align="right"/></div>' % file_name
extra.append(pytest_html.extras.html(html))
report.extra = extra
It also creates Jira ticket with a description and screenshot. What I would like to pass as "Description" is basically the log (which I already have) plus the assertion failure information.
Is there a way of getting the info here and passing it?
Is there, perhaps, a better way to create the ticket for a failed test?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要添加输出和断言失败信息作为测试输出,只需添加以下参数:
:) :)
如果将其包含在JIRA中,则在很大程度上取决于您如何从HTML报告中创建此票。这样可以肯定的是,您将其在报告中。
To add output and assertion failure information as test output, just add following argument:
And basically, that's all :)
If that will be contained in your jira, it depends highly how you create this ticket from HTML report. That way for sure you get it in report.