Skip to content

Commit 1a70489

Browse files
authored
Use user-data to pass link patterns to Allure-Behave (fixes #463 via #464 )
1 parent f8f36cc commit 1a70489

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

allure-behave/src/listener.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def start_scenario(self, scenario):
9797
test_case.description = '\n'.join(scenario.description)
9898
test_case.parameters = scenario_parameters(scenario)
9999

100-
test_case.links.extend(scenario_links(scenario))
100+
issue_pattern = self.behave_config.userdata.get('AllureFormatter.issue_pattern', None)
101+
link_pattern = self.behave_config.userdata.get('AllureFormatter.link_pattern', None)
102+
test_case.links.extend(scenario_links(scenario, issue_pattern=issue_pattern, link_pattern=link_pattern))
101103
test_case.labels.extend(scenario_labels(scenario))
102104
test_case.labels.append(Label(name=LabelType.FEATURE, value=scenario.feature.name))
103105
test_case.labels.append(Label(name=LabelType.FRAMEWORK, value='behave'))

allure-behave/src/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ def scenario_parameters(scenario):
3838
return [Parameter(name=name, value=value) for name, value in zip(row.headings, row.cells)] if row else None
3939

4040

41-
def scenario_links(scenario):
41+
def scenario_links(scenario, issue_pattern, link_pattern):
4242
tags = scenario.feature.tags + scenario.tags
43-
parsed = [parse_tag(item) for item in tags]
43+
parsed = [
44+
parse_tag(item, issue_pattern=issue_pattern, link_pattern=link_pattern)
45+
for item in tags
46+
]
4447
return filter(lambda x: isinstance(x, Link), parsed)
4548

4649

allure-python-commons/src/mapping.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __is(kind, t):
1313
return kind in [v for k, v in t.__dict__.items() if not k.startswith('__')]
1414

1515

16-
def parse_tag(tag):
16+
def parse_tag(tag, *, issue_pattern=None, link_pattern=None):
1717
"""
1818
>>> parse_tag("blocker")
1919
Label(name='severity', value='blocker')
@@ -48,6 +48,10 @@ def parse_tag(tag):
4848
if prefix == TAG_PREFIX and value is not None:
4949

5050
if __is(kind, LinkType):
51+
if issue_pattern and kind == "issue" and not value.startswith("http"):
52+
value = issue_pattern.format(value)
53+
if link_pattern and kind == "link" and not value.startswith("http"):
54+
value = issue_pattern.format(value)
5155
return Link(type=kind, name=name or value, url=value)
5256

5357
if __is(kind, LabelType):

0 commit comments

Comments
 (0)