@@ -72,36 +72,57 @@ def __call__(cls, *args, **kwargs):
7272
7373
7474class PyTestServiceClass (with_metaclass (Singleton , object )):
75+ """Pytest service class for reporting test results to the Report Portal."""
7576
7677 def __init__ (self ):
78+ """Initialize instance attributes."""
79+ self ._agent_name = 'pytest-reportportal'
80+ self ._errors = queue .Queue ()
81+ self ._hier_parts = {}
82+ self ._issue_types = {}
83+ self ._item_parts = {}
84+ self ._loglevels = ('TRACE' , 'DEBUG' , 'INFO' , 'WARN' , 'ERROR' )
85+ self .ignore_errors = True
86+ self .ignored_tags = []
87+ self .log_batch_size = 20
88+ self .log_item_id = None
89+ self .parent_item_id = None
7790 self .rp = None
7891 self .rp_supports_parameters = True
7992 try :
8093 pkg_resources .get_distribution ('reportportal_client >= 3.2.0' )
8194 except pkg_resources .VersionConflict :
8295 self .rp_supports_parameters = False
8396
84- self .log_item_id = None
85- self .parent_item_id = None
86-
87- self .ignore_errors = True
88- self .ignored_tags = []
89-
90- self ._errors = queue .Queue ()
91- self ._loglevels = ('TRACE' , 'DEBUG' , 'INFO' , 'WARN' , 'ERROR' )
92- self ._hier_parts = {}
93- self ._item_parts = {}
94-
95- def init_service (self , endpoint , project , uuid , log_batch_size ,
96- ignore_errors , ignored_tags , verify_ssl = True ,
97+ @property
98+ def issue_types (self ):
99+ """Issue types for the Report Portal project."""
100+ if not self ._issue_types :
101+ if not self .project_settings :
102+ return self ._issue_types
103+ for item_type in ("AUTOMATION_BUG" , "PRODUCT_BUG" , "SYSTEM_ISSUE" ,
104+ "NO_DEFECT" , "TO_INVESTIGATE" ):
105+ for item in self .project_settings ["subTypes" ][item_type ]:
106+ self ._issue_types [item ["shortName" ]] = item ["locator" ]
107+ return self ._issue_types
108+
109+ def init_service (self ,
110+ endpoint ,
111+ project ,
112+ uuid ,
113+ log_batch_size ,
114+ ignore_errors ,
115+ ignored_tags ,
116+ verify_ssl = True ,
97117 retries = 0 ):
118+ """Update self.rp with the instance of the ReportPortalService."""
98119 self ._errors = queue .Queue ()
99120 if self .rp is None :
100121 self .ignore_errors = ignore_errors
122+ self .ignored_tags = ignored_tags
101123 if self .rp_supports_parameters :
102- self .ignored_tags = list (set (ignored_tags ).union ({'parametrize' }))
103- else :
104- self .ignored_tags = ignored_tags
124+ self .ignored_tags = list (
125+ set (ignored_tags ).union ({'parametrize' }))
105126 log .debug ('ReportPortal - Init service: endpoint=%s, '
106127 'project=%s, uuid=%s' , endpoint , project , uuid )
107128 self .rp = ReportPortalService (
@@ -111,19 +132,13 @@ def init_service(self, endpoint, project, uuid, log_batch_size,
111132 retries = retries ,
112133 verify_ssl = verify_ssl
113134 )
135+ self .project_settings = None
114136 if self .rp and hasattr (self .rp , "get_project_settings" ):
115137 self .project_settings = self .rp .get_project_settings ()
116- else :
117- self .project_settings = None
118- self .issue_types = self .get_issue_types ()
119138 else :
120139 log .debug ('The pytest is already initialized' )
121140 return self .rp
122141
123- def async_error_handler (self , exc_info ):
124- self .rp = None
125- self ._errors .put_nowait (exc_info )
126-
127142 def start_launch (self ,
128143 launch_name ,
129144 mode = None ,
@@ -133,7 +148,10 @@ def start_launch(self,
133148 if self .rp is None :
134149 return
135150
151+ system_info = self .rp .get_system_information (self ._agent_name )
152+ system_info ['system' ] = True
136153 sl_pt = {
154+ 'attributes' : system_info ,
137155 'name' : launch_name ,
138156 'start_time' : timestamp (),
139157 'description' : description ,
@@ -281,8 +299,7 @@ def finish_pytest_item(self, test_item, item_id, status, issue=None):
281299 log .debug ('ReportPortal - Finish TestItem: request_body=%s' , fta_rq )
282300
283301 parts = self ._item_parts [test_item ]
284- if not parts :
285- self .rp .finish_test_item (** fta_rq )
302+ self .rp .finish_test_item (** fta_rq )
286303 while len (parts ) > 0 :
287304 part = parts .pop ()
288305 if status == "FAILED" :
@@ -323,12 +340,13 @@ def post_log(self, message, loglevel='INFO', attachment=None):
323340 loglevel = 'INFO'
324341
325342 sl_rq = {
343+ 'item_id' : self .log_item_id ,
326344 'time' : timestamp (),
327345 'message' : message ,
328346 'level' : loglevel ,
329- 'attachment' : attachment ,
347+ 'attachment' : attachment
330348 }
331- self .rp .log_batch (( sl_rq ,), item_id = self . log_item_id )
349+ self .rp .log ( ** sl_rq )
332350
333351 def _stop_if_necessary (self ):
334352 try :
@@ -340,17 +358,6 @@ def _stop_if_necessary(self):
340358 except queue .Empty :
341359 pass
342360
343- def get_issue_types (self ):
344- issue_types = {}
345- if not self .project_settings :
346- return issue_types
347-
348- for item_type in ("AUTOMATION_BUG" , "PRODUCT_BUG" , "SYSTEM_ISSUE" , "NO_DEFECT" , "TO_INVESTIGATE" ):
349- for item in self .project_settings ["subTypes" ][item_type ]:
350- issue_types [item ["shortName" ]] = item ["locator" ]
351-
352- return issue_types
353-
354361 @staticmethod
355362 def _add_item_hier_parts_dirs (item , hier_flag , dirs_level , report_parts , dirs_parts , rp_name = "" ):
356363
0 commit comments