|
6 | 6 | from allure_commons.utils import uuid4
|
7 | 7 | from allure_commons.utils import now
|
8 | 8 | from allure_commons.utils import platform_label
|
9 |
| -from allure_commons.types import LabelType, AttachmentType |
| 9 | +from allure_commons.types import LabelType, AttachmentType, LinkType |
10 | 10 | from allure_commons.model2 import TestResult
|
11 | 11 | from allure_commons.model2 import TestStepResult
|
12 | 12 | from allure_commons.model2 import TestBeforeResult, TestAfterResult
|
13 | 13 | from allure_commons.model2 import TestResultContainer
|
14 |
| -from allure_commons.model2 import Parameter, Label |
| 14 | +from allure_commons.model2 import Parameter, Label, Link |
15 | 15 | from allure_behave.utils import scenario_parameters
|
16 | 16 | from allure_behave.utils import scenario_name
|
17 | 17 | from allure_behave.utils import scenario_history_id
|
|
33 | 33 | class AllureListener(object):
|
34 | 34 | def __init__(self, behave_config):
|
35 | 35 | self.behave_config = behave_config
|
| 36 | + self.issue_pattern = behave_config.userdata.get('AllureFormatter.issue_pattern', None) |
| 37 | + self.link_pattern = behave_config.userdata.get('AllureFormatter.link_pattern', None) |
36 | 38 | self.logger = AllureReporter()
|
37 | 39 | self.current_step_uuid = None
|
38 | 40 | self.current_scenario_uuid = None
|
@@ -100,9 +102,10 @@ def start_scenario(self, scenario):
|
100 | 102 | test_case.description = '\n'.join(scenario.description)
|
101 | 103 | test_case.parameters = scenario_parameters(scenario)
|
102 | 104 |
|
103 |
| - issue_pattern = self.behave_config.userdata.get('AllureFormatter.issue_pattern', None) |
104 |
| - link_pattern = self.behave_config.userdata.get('AllureFormatter.link_pattern', None) |
105 |
| - test_case.links.extend(scenario_links(scenario, issue_pattern=issue_pattern, link_pattern=link_pattern)) |
| 105 | + test_case.links.extend(scenario_links( |
| 106 | + scenario, |
| 107 | + issue_pattern=self.issue_pattern, |
| 108 | + link_pattern=self.link_pattern)) |
106 | 109 | test_case.labels.extend(scenario_labels(scenario))
|
107 | 110 | test_case.labels.append(Label(name=LabelType.FEATURE, value=scenario.feature.name))
|
108 | 111 | test_case.labels.append(Label(name=LabelType.FRAMEWORK, value='behave'))
|
@@ -191,6 +194,36 @@ def attach_data(self, body, name, attachment_type, extension):
|
191 | 194 | def attach_file(self, source, name, attachment_type, extension):
|
192 | 195 | self.logger.attach_file(uuid4(), source, name=name, attachment_type=attachment_type, extension=extension)
|
193 | 196 |
|
| 197 | + @allure_commons.hookimpl |
| 198 | + def add_description(self, test_description): |
| 199 | + test_result = self.logger.get_test(None) |
| 200 | + if test_result: |
| 201 | + test_result.description = test_description |
| 202 | + |
| 203 | + @allure_commons.hookimpl |
| 204 | + def add_description_html(self, test_description_html): |
| 205 | + test_result = self.logger.get_test(None) |
| 206 | + if test_result: |
| 207 | + test_result.descriptionHtml = test_description_html |
| 208 | + |
| 209 | + @allure_commons.hookimpl |
| 210 | + def add_link(self, url, link_type, name): |
| 211 | + test_result = self.logger.get_test(None) |
| 212 | + if test_result: |
| 213 | + pattern = u'{}' |
| 214 | + if link_type == LinkType.ISSUE and self.issue_pattern: |
| 215 | + pattern = self.issue_pattern |
| 216 | + elif link_type == LinkType.LINK and self.link_pattern: |
| 217 | + pattern = self.link_pattern |
| 218 | + |
| 219 | + link_url = pattern.format(url) |
| 220 | + new_link = Link(link_type, link_url, link_url if name is None else name) |
| 221 | + for link in test_result.links: |
| 222 | + if link.url == new_link.url: |
| 223 | + return |
| 224 | + |
| 225 | + test_result.links.append(new_link) |
| 226 | + |
194 | 227 |
|
195 | 228 | class Context(list):
|
196 | 229 | def __init__(self, _list=list()):
|
|
0 commit comments