66from allure_commons .utils import uuid4
77from allure_commons .utils import now
88from allure_commons .utils import platform_label
9- from allure_commons .types import LabelType , AttachmentType
9+ from allure_commons .types import LabelType , AttachmentType , LinkType
1010from allure_commons .model2 import TestResult
1111from allure_commons .model2 import TestStepResult
1212from allure_commons .model2 import TestBeforeResult , TestAfterResult
1313from allure_commons .model2 import TestResultContainer
14- from allure_commons .model2 import Parameter , Label
14+ from allure_commons .model2 import Parameter , Label , Link
1515from allure_behave .utils import scenario_parameters
1616from allure_behave .utils import scenario_name
1717from allure_behave .utils import scenario_history_id
3333class AllureListener (object ):
3434 def __init__ (self , behave_config ):
3535 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 )
38+ self .hide_excluded = behave_config .userdata .get ('AllureFormatter.hide_excluded' , False )
3639 self .logger = AllureReporter ()
3740 self .current_step_uuid = None
3841 self .current_scenario_uuid = None
@@ -100,9 +103,10 @@ def start_scenario(self, scenario):
100103 test_case .description = '\n ' .join (scenario .description )
101104 test_case .parameters = scenario_parameters (scenario )
102105
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 ))
106+ test_case .links .extend (scenario_links (
107+ scenario ,
108+ issue_pattern = self .issue_pattern ,
109+ link_pattern = self .link_pattern ))
106110 test_case .labels .extend (scenario_labels (scenario ))
107111 test_case .labels .append (Label (name = LabelType .FEATURE , value = scenario .feature .name ))
108112 test_case .labels .append (Label (name = LabelType .FRAMEWORK , value = 'behave' ))
@@ -115,8 +119,12 @@ def stop_test(self, parent_uuid, uuid, name, context, exc_type, exc_val, exc_tb)
115119 self .stop_scenario (context ['scenario' ])
116120
117121 def stop_scenario (self , scenario ):
118- if scenario .status == 'skipped' \
119- and not self .behave_config .show_skipped or scenario .skip_reason == TEST_PLAN_SKIP_REASON :
122+ should_run = (scenario .should_run_with_tags (self .behave_config .tags ) and
123+ scenario .should_run_with_name_select (self .behave_config ))
124+ should_drop_skipped_by_option = scenario .status == 'skipped' and not self .behave_config .show_skipped
125+ should_drop_excluded = self .hide_excluded and (scenario .skip_reason == TEST_PLAN_SKIP_REASON or not should_run )
126+
127+ if should_drop_skipped_by_option or should_drop_excluded :
120128 self .logger .drop_test (self .current_scenario_uuid )
121129 else :
122130 status = scenario_status (scenario )
@@ -191,6 +199,36 @@ def attach_data(self, body, name, attachment_type, extension):
191199 def attach_file (self , source , name , attachment_type , extension ):
192200 self .logger .attach_file (uuid4 (), source , name = name , attachment_type = attachment_type , extension = extension )
193201
202+ @allure_commons .hookimpl
203+ def add_description (self , test_description ):
204+ test_result = self .logger .get_test (None )
205+ if test_result :
206+ test_result .description = test_description
207+
208+ @allure_commons .hookimpl
209+ def add_description_html (self , test_description_html ):
210+ test_result = self .logger .get_test (None )
211+ if test_result :
212+ test_result .descriptionHtml = test_description_html
213+
214+ @allure_commons .hookimpl
215+ def add_link (self , url , link_type , name ):
216+ test_result = self .logger .get_test (None )
217+ if test_result :
218+ pattern = u'{}'
219+ if link_type == LinkType .ISSUE and self .issue_pattern :
220+ pattern = self .issue_pattern
221+ elif link_type == LinkType .LINK and self .link_pattern :
222+ pattern = self .link_pattern
223+
224+ link_url = pattern .format (url )
225+ new_link = Link (link_type , link_url , link_url if name is None else name )
226+ for link in test_result .links :
227+ if link .url == new_link .url :
228+ return
229+
230+ test_result .links .append (new_link )
231+
194232
195233class Context (list ):
196234 def __init__ (self , _list = list ()):
0 commit comments