5050 get_package_version
5151)
5252
53- log = logging .getLogger (__name__ )
53+ LOGGER = logging .getLogger (__name__ )
5454
5555MAX_ITEM_NAME_LENGTH : int = 1024
5656TRUNCATION_STR : str = '...'
@@ -204,9 +204,9 @@ def start_launch(self) -> Optional[str]:
204204 :return: item ID
205205 """
206206 sl_pt = self ._build_start_launch_rq ()
207- log .debug ('ReportPortal - Start launch: request_body=%s' , sl_pt )
207+ LOGGER .debug ('ReportPortal - Start launch: request_body=%s' , sl_pt )
208208 self ._launch_id = self .rp .start_launch (** sl_pt )
209- log .debug ('ReportPortal - Launch started: id=%s' , self ._launch_id )
209+ LOGGER .debug ('ReportPortal - Launch started: id=%s' , self ._launch_id )
210210 return self ._launch_id
211211
212212 def _get_item_dirs (self , item : Item ) -> List [str ]:
@@ -366,7 +366,7 @@ def _get_item_name(self, name: str) -> str:
366366 """
367367 if len (name ) > MAX_ITEM_NAME_LENGTH :
368368 name = name [:MAX_ITEM_NAME_LENGTH - len (TRUNCATION_STR )] + TRUNCATION_STR
369- log .warning (PytestWarning (
369+ LOGGER .warning (PytestWarning (
370370 f'Test leaf ID was truncated to "{ name } " because of name size constrains on Report Portal' ))
371371 return name
372372
@@ -411,8 +411,7 @@ def _build_start_suite_rq(self, leaf):
411411 return payload
412412
413413 def _start_suite (self , suite_rq ):
414- log .debug ('ReportPortal - Start Suite: request_body=%s' ,
415- suite_rq )
414+ LOGGER .debug ('ReportPortal - Start Suite: request_body=%s' , suite_rq )
416415 return self .rp .start_test_item (** suite_rq )
417416
418417 def _create_suite (self , leaf ):
@@ -655,7 +654,7 @@ def _build_start_step_rq(self, leaf):
655654 return payload
656655
657656 def _start_step (self , step_rq ):
658- log .debug ('ReportPortal - Start TestItem: request_body=%s' , step_rq )
657+ LOGGER .debug ('ReportPortal - Start TestItem: request_body=%s' , step_rq )
659658 return self .rp .start_test_item (** step_rq )
660659
661660 def __unique_id (self ):
@@ -729,11 +728,11 @@ def _build_finish_step_rq(self, leaf):
729728 return payload
730729
731730 def _finish_step (self , finish_rq ):
732- log .debug ('ReportPortal - Finish TestItem: request_body=%s' , finish_rq )
731+ LOGGER .debug ('ReportPortal - Finish TestItem: request_body=%s' , finish_rq )
733732 self .rp .finish_test_item (** finish_rq )
734733
735734 def _finish_suite (self , finish_rq ):
736- log .debug ('ReportPortal - End TestSuite: request_body=%s' , finish_rq )
735+ LOGGER .debug ('ReportPortal - End TestSuite: request_body=%s' , finish_rq )
737736 self .rp .finish_test_item (** finish_rq )
738737
739738 def _build_finish_suite_rq (self , leaf ):
@@ -815,7 +814,7 @@ def _build_finish_launch_rq(self):
815814 return finish_rq
816815
817816 def _finish_launch (self , finish_rq ):
818- log .debug ('ReportPortal - Finish launch: request_body=%s' , finish_rq )
817+ LOGGER .debug ('ReportPortal - Finish launch: request_body=%s' , finish_rq )
819818 self .rp .finish_launch (** finish_rq )
820819
821820 @check_rp_enabled
@@ -828,8 +827,19 @@ def finish_launch(self):
828827 # To finish launch session str parameter is needed
829828 self ._finish_launch (self ._build_finish_launch_rq ())
830829
830+ def _build_log (self , item_id : str , message : str , log_level : str , attachment : Optional [Any ] = None ):
831+ sl_rq = {
832+ 'item_id' : item_id ,
833+ 'time' : timestamp (),
834+ 'message' : message ,
835+ 'level' : log_level ,
836+ }
837+ if attachment :
838+ sl_rq ['attachment' ] = attachment
839+ return sl_rq
840+
831841 @check_rp_enabled
832- def post_log (self , test_item , message , log_level = 'INFO' , attachment = None ):
842+ def post_log (self , test_item , message : str , log_level : str = 'INFO' , attachment : Optional [ Any ] = None ):
833843 """
834844 Send a log message to the Report Portal.
835845
@@ -841,16 +851,11 @@ def post_log(self, test_item, message, log_level='INFO', attachment=None):
841851 :return: None
842852 """
843853 if log_level not in self ._log_levels :
844- log .warning ('Incorrect loglevel = %s. Force set to INFO. '
845- 'Available levels: %s.' , log_level , self ._log_levels )
854+ LOGGER .warning ('Incorrect loglevel = %s. Force set to INFO. '
855+ 'Available levels: %s.' , log_level , self ._log_levels )
846856 item_id = self ._tree_path [test_item ][- 1 ]['item_id' ]
847- sl_rq = {
848- 'item_id' : item_id ,
849- 'time' : timestamp (),
850- 'message' : message ,
851- 'level' : log_level ,
852- 'attachment' : attachment
853- }
857+
858+ sl_rq = self ._build_log (item_id , message , log_level , attachment )
854859 self .rp .log (** sl_rq )
855860
856861 def report_fixture (self , name : str , error_msg : str ) -> None :
@@ -864,15 +869,15 @@ def report_fixture(self, name: str, error_msg: str) -> None:
864869
865870 try :
866871 outcome = yield
867- if outcome .exception :
868- log . error ( error_msg )
869- log . exception ( outcome . exception )
870- reporter . finish_nested_step ( item_id , timestamp (), 'FAILED' )
871- else :
872- reporter .finish_nested_step (item_id , timestamp (), 'PASSED' )
872+ exception = outcome .exception
873+ status = 'PASSED'
874+ if exception :
875+ if type ( exception ). __name__ != 'Skipped' :
876+ status = 'FAILED'
877+ reporter .finish_nested_step (item_id , timestamp (), status )
873878 except Exception as e :
874- log .error ('Failed to report fixture: %s' , name )
875- log .exception (e )
879+ LOGGER .error ('Failed to report fixture: %s' , name )
880+ LOGGER .exception (e )
876881 reporter .finish_nested_step (item_id , timestamp (), 'FAILED' )
877882
878883 def start (self ) -> None :
@@ -883,9 +888,9 @@ def start(self) -> None:
883888 self ._config .rp_ignore_attributes or []
884889 ).union ({'parametrize' })
885890 )
886- log .debug ('ReportPortal - Init service: endpoint=%s, '
887- 'project=%s, api_key=%s' , self ._config .rp_endpoint ,
888- self ._config .rp_project , self ._config .rp_api_key )
891+ LOGGER .debug ('ReportPortal - Init service: endpoint=%s, '
892+ 'project=%s, api_key=%s' , self ._config .rp_endpoint ,
893+ self ._config .rp_project , self ._config .rp_api_key )
889894 launch_id = self ._launch_id
890895 if self ._config .rp_launch_id :
891896 launch_id = self ._config .rp_launch_id
0 commit comments