创建使用PYTEST中失败测试的错误消息创建JIRA票证

发布于 2025-01-28 01:40:51 字数 973 浏览 4 评论 0原文

我有一个代码生成报告并在测试失败时添加屏幕截图:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与之呼应 2025-02-04 01:40:51

要添加输出和断言失败信息作为测试输出,只需添加以下参数:

python3 -m pytest (...) --capture=sys (...)

:) :)

如果将其包含在JIRA中,则在很大程度上取决于您如何从HTML报告中创建此票。这样可以肯定的是,您将其在报告中。

To add output and assertion failure information as test output, just add following argument:

python3 -m pytest (...) --capture=sys (...)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文