Skip to content

Commit a0fa2ca

Browse files
Quronsseliverstov
authored andcommitted
exclude duplicate links in report (via allure-framework#414)
1 parent f2a4d6d commit a0fa2ca

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

allure-pytest/src/listener.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,12 @@ def add_link(self, url, link_type, name):
242242
test_result = self.allure_logger.get_test(None)
243243
if test_result:
244244
pattern = dict(self.config.option.allure_link_pattern).get(link_type, u'{}')
245-
url = pattern.format(url)
246-
test_result.links.append(Link(link_type, url, name))
245+
link_url = pattern.format(url)
246+
new_link = Link(link_type, link_url, link_url if name is None else name)
247+
for link in test_result.links:
248+
if link.url == new_link.url:
249+
return
250+
test_result.links.append(new_link)
247251

248252
@allure_commons.hookimpl
249253
def add_label(self, label_type, labels):

allure-pytest/test/acceptance/link/dynamic_link_test.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" ./examples/link/dynamic_link.rst """
22

33
import pytest
4-
from hamcrest import assert_that
4+
from hamcrest import assert_that, equal_to
55
from allure_commons_test.report import has_test_case
66
from allure_commons_test.result import has_link
77
from allure_commons_test.result import has_issue_link
@@ -28,7 +28,19 @@ def test_all_links_together(executed_docstring_path):
2828
assert_that(executed_docstring_path.allure_report,
2929
has_test_case("test_all_links_together",
3030
has_issue_link("issues/24"),
31-
has_issue_link("issues/24"),
31+
has_issue_link("issues/132"),
3232
has_link("allure", name="QAMETA", link_type="docs")
3333
)
3434
)
35+
36+
37+
def test_unique_dynamic_links(executed_docstring_source):
38+
"""
39+
>>> import allure
40+
41+
>>> def test_unique_dynamic_links_example():
42+
... allure.dynamic.link("some/unique/dynamic/link")
43+
... allure.dynamic.link("some/unique/dynamic/link")
44+
"""
45+
assert_that(executed_docstring_source.allure_report.test_cases[0]['links'],
46+
equal_to([{'url': u'some/unique/dynamic/link', 'type': 'link', 'name': u'some/unique/dynamic/link'}]))

allure-python-commons-test/src/result.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,3 @@ def with_trace_contains(string):
159159

160160
def has_history_id():
161161
return has_entry('historyId', anything())
162-

0 commit comments

Comments
 (0)