在Allure报告中,如何通过Python与名称和链接建立链接



我想创建具有该项目名称和链接的链接。

报告中的示例我有链接名称 - 任务55188,此链接将我重定向到'http://tfs.com/tfs/company/rnd/QA/_testManagement?planId=41890&suiteId=55188&_a=tests'

但是如何在Python代码中创建这个?

带有装饰器

一些诱人的python集成允许使用CMD线开关设置链接模式。例如:

hallure-pytest:

--allure-link-pattern=http://tfs.com/tfs/company/rnd/QA/_testManagement?planId=41890&suiteId={}&_a=tests

Allure-Behave:

-D AllureFormatter.link_pattern=http://tfs.com/tfs/company/rnd/QA/_testManagement?planId=41890&suiteId={}&_a=tests

设置链接模式时,您无需像Viktoriia的答案中创建自己的allure_wrapper.py,并且可以直接使用@allure.link:55188


动态

除了上面的装饰方法外,Dynamic类还可以在运行时动态添加到报告的链接。例如:

import allure
def some_test_function():
    allure.dynamic.link('http://tfs.com/tfs/company/rnd/QA/_testManagement?planId=41890&suiteId=55188&_a=tests', name='55188')

某些集成可能不支持动态链接,并且在调用allure.dynamic.link时不会做任何事情。例如,我必须通过在pr。

我们使用动态链接有条件地添加JIRA缺陷链接以进行失败测试。当测试失败时,我们会创建一个具有特定标签的JIRA缺陷。下次测试失败时,它会查询JIRA REST API以查找与标签匹配并链接它们的所有问题。这样,我们可以添加/删除JIRA中的测试链接,并避免在测试代码中与装饰器四处张望。

您可以在项目内创建yellure_wrapper.py文件,并使用带有任务编号/任务标题的装饰器。

例如:

在您的项目中,您有一个任务列表:

ststartants.py

TASKS = {
    '55188': 'Test task'
}

导入此列表,并在allure_wrapper.py中用于任务装饰

allure_wrapper.py

from constants import TASKS
from allure import link, issue, story
# Specify your link pattern
TFS_LINK_PATTERN = 'http://tfs.com/tfs/company/rnd/QA/_testManagement?planId=41890&suiteId={}&_a=tests'
def task_link(task_id):
return link(TFS_LINK_PATTERN.format(task_id), name=f'{item_type} {task_id}')
def task_links(links):
decos = []
for link in links:
    decos.append(task_link(link))
    decos.append(story(TASKS[link]))
return compose_decos(decos)
def compose_decos(decos):
    def composition(func):
        for deco in reversed(decos):
            func = deco(func)
        return func
    return composition

使用创建的装饰器连接链接:

from allure_wrapper import task_links
@task_links(['55188'])
def test_task_link():
    # do smth

作为结果,您的魅力报告中将有可单击的链接

我为此做了解决方法:

allure.attach('<head></head><body><a href="' + your_link + '">Link to ...</a></body>', 'Logs', allure.attachment_type.HTML)

最新更新