Skip to content

Commit 884581f

Browse files
authored
fix dynamic issue (fixes allure-framework#198 via allure-framework#200)
1 parent b54580c commit 884581f

File tree

5 files changed

+41
-17
lines changed

5 files changed

+41
-17
lines changed

allure-pytest/src/listener.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
class AllureListener(object):
2525

26-
def __init__(self):
26+
def __init__(self, config):
27+
self.config = config
2728
self.allure_logger = AllureReporter()
2829
self._cache = ItemCache()
2930
self._host = host_tag()
@@ -211,6 +212,8 @@ def add_description_html(self, test_description_html):
211212
def add_link(self, url, link_type, name):
212213
test_result = self.allure_logger.get_test(None)
213214
if test_result:
215+
pattern = dict(self.config.option.allure_link_pattern).get(link_type, u'{}')
216+
url = pattern.format(url)
214217
test_result.links.append(Link(link_type, url, name))
215218

216219
@allure_commons.hookimpl

allure-pytest/src/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def pytest_configure(config):
9494
allure_commons.plugin_manager.register(test_helper)
9595

9696
if report_dir:
97-
test_listener = AllureListener()
97+
test_listener = AllureListener(config)
9898
config.pluginmanager.register(test_listener)
9999
allure_commons.plugin_manager.register(test_listener)
100100

allure-pytest/test/links/dynamic_links_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
LINK_1 = "https://github.com"
55
LINK_2 = "https://gitter.im"
6+
ISSUE = 'https://github.com/allure-framework/allure-python/pull/199'
67

78

89
@allure.link(LINK_1)
@@ -30,3 +31,4 @@ def test_parametrized_dynamic_links(link):
3031
... )
3132
"""
3233
allure.dynamic.link(link)
34+
allure.dynamic.issue(ISSUE)
Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
"""
2-
>>> allure_report = getfixture('allure_report_with_params')('--allure-link-pattern=issue:{pattern}'.format(
3-
... pattern=ISSUE_PATTERN),
4-
... '--allure-link-pattern={link_type}:{pattern}'.format(
5-
... link_type=CUSTOM_LINK_TYPE,
6-
... pattern=CUSTOM_LINK_PATTERN))
7-
>>> assert_that(allure_report,
8-
... has_test_case('test_link_pattern',
9-
... has_link(ISSUE_PATTERN.format(ISSUE)),
10-
... has_link(CUSTOM_LINK_PATTERN.format(CUSTOM_LINK))
11-
... )
12-
... )
13-
"""
14-
151
import pytest
2+
import allure
3+
164

175
ISSUE = '24'
186
ISSUE_PATTERN = 'https://github.com/allure-framework/allure-python2/issues/{}'
@@ -24,4 +12,35 @@
2412
@pytest.allure.issue(ISSUE)
2513
@pytest.allure.link(CUSTOM_LINK, link_type=CUSTOM_LINK_TYPE)
2614
def test_link_pattern():
15+
"""
16+
>>> allure_report = getfixture('allure_report_with_params')('--allure-link-pattern=issue:{pattern}'.format(
17+
... pattern=ISSUE_PATTERN),
18+
... '--allure-link-pattern={link_type}:{pattern}'.format(
19+
... link_type=CUSTOM_LINK_TYPE,
20+
... pattern=CUSTOM_LINK_PATTERN))
21+
>>> assert_that(allure_report,
22+
... has_test_case('test_link_pattern',
23+
... has_link(ISSUE_PATTERN.format(ISSUE)),
24+
... has_link(CUSTOM_LINK_PATTERN.format(CUSTOM_LINK))
25+
... )
26+
... )
27+
"""
2728
pass
29+
30+
31+
def test_dynamic_link_pattern():
32+
"""
33+
>>> allure_report = getfixture('allure_report_with_params')('--allure-link-pattern=issue:{pattern}'.format(
34+
... pattern=ISSUE_PATTERN),
35+
... '--allure-link-pattern={link_type}:{pattern}'.format(
36+
... link_type=CUSTOM_LINK_TYPE,
37+
... pattern=CUSTOM_LINK_PATTERN))
38+
>>> assert_that(allure_report,
39+
... has_test_case('test_dynamic_link_pattern',
40+
... has_link(ISSUE_PATTERN.format(ISSUE)),
41+
... has_link(CUSTOM_LINK_PATTERN.format(CUSTOM_LINK))
42+
... )
43+
... )
44+
"""
45+
allure.dynamic.issue(ISSUE)
46+
allure.dynamic.link(CUSTOM_LINK, link_type=CUSTOM_LINK_TYPE)

allure-python-commons/src/_allure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def link(url, link_type=LinkType.LINK, name=None):
103103

104104
@staticmethod
105105
def issue(url, name=None):
106-
Dynamic.link(url, link_type=LinkType.TEST_CASE, name=name)
106+
Dynamic.link(url, link_type=LinkType.ISSUE, name=name)
107107

108108
@staticmethod
109109
def testcase(url, name=None):

0 commit comments

Comments
 (0)