2020import re
2121from functools import wraps
2222from mimetypes import guess_type
23- from types import MappingProxyType
2423from typing import Optional , Dict , Union , Any
2524from warnings import warn
2625
27- from reportportal_client .helpers import gen_attributes , LifoQueue , is_binary , guess_content_type_from_bytes
26+ from reportportal_client .helpers import LifoQueue , is_binary , guess_content_type_from_bytes
2827
2928from .model import Keyword , Launch , Test , LogMessage , Suite
3029from .service import RobotService
31- from .static import MAIN_SUITE_ID , PABOT_WIHOUT_LAUNCH_ID_MSG
30+ from .static import MAIN_SUITE_ID , PABOT_WITHOUT_LAUNCH_ID_MSG
3231from .variables import Variables
3332
3433logger = logging .getLogger (__name__ )
3534VARIABLE_PATTERN = r'^\s*\${[^}]*}\s*=\s*'
3635TRUNCATION_SIGN = "...'"
37- CONTENT_TYPE_TO_EXTENSIONS = MappingProxyType ({
38- 'application/pdf' : 'pdf' ,
39- 'application/zip' : 'zip' ,
40- 'application/java-archive' : 'jar' ,
41- 'image/jpeg' : 'jpg' ,
42- 'image/png' : 'png' ,
43- 'image/gif' : 'gif' ,
44- 'image/bmp' : 'bmp' ,
45- 'image/vnd.microsoft.icon' : 'ico' ,
46- 'image/webp' : 'webp' ,
47- 'audio/mpeg' : 'mp3' ,
48- 'audio/wav' : 'wav' ,
49- 'video/mpeg' : 'mpeg' ,
50- 'video/avi' : 'avi' ,
51- 'video/webm' : 'webm' ,
52- 'text/plain' : 'txt' ,
53- 'application/octet-stream' : 'bin'
54- })
5536
5637
5738def _unescape (binary_string : str , stop_at : int = - 1 ):
@@ -106,9 +87,9 @@ def wrap(*args, **kwargs):
10687class listener :
10788 """Robot Framework listener interface for reporting to ReportPortal."""
10889
109- _items : LifoQueue = ...
110- _service : Optional [RobotService ] = ...
111- _variables : Optional [Variables ] = ...
90+ _items : LifoQueue
91+ _service : Optional [RobotService ]
92+ _variables : Optional [Variables ]
11293 ROBOT_LISTENER_API_VERSION = 2
11394
11495 def __init__ (self ) -> None :
@@ -165,7 +146,7 @@ def log_message(self, message: Dict) -> None:
165146 msg .message = (f'Binary data of type "{ content_type } " logging skipped, as it was processed as text and'
166147 ' hence corrupted.' )
167148 msg .level = 'WARN'
168- logger .debug ('ReportPortal - Log Message: {0}' . format ( message ) )
149+ logger .debug (f 'ReportPortal - Log Message: { message } ' )
169150 self .service .log (message = msg )
170151
171152 @check_rp_enabled
@@ -182,8 +163,7 @@ def log_message_with_image(self, msg: Dict, image: str):
182163 'data' : fh .read (),
183164 'mime' : guess_type (image )[0 ] or 'application/octet-stream'
184165 }
185- logger .debug ('ReportPortal - Log Message with Image: {0} {1}'
186- .format (mes , image ))
166+ logger .debug (f'ReportPortal - Log Message with Image: { mes } { image } ' )
187167 self .service .log (message = mes )
188168
189169 @property
@@ -207,18 +187,17 @@ def variables(self) -> Variables:
207187 return self ._variables
208188
209189 @check_rp_enabled
210- def start_launch (self , attributes : Dict , ts : Optional [Any ] = None ) -> None :
190+ def start_launch (self , attributes : Dict [ str , Any ] , ts : Optional [Any ] = None ) -> None :
211191 """Start a new launch at the ReportPortal.
212192
213193 :param attributes: Dictionary passed by the Robot Framework
214194 :param ts: Timestamp(used by the ResultVisitor)
215195 """
216- launch = Launch (self .variables .launch_name , attributes )
217- launch .attributes = gen_attributes (self .variables .launch_attributes )
196+ launch = Launch (self .variables .launch_name , attributes , self .variables .launch_attributes )
218197 launch .doc = self .variables .launch_doc or launch .doc
219198 if self .variables .pabot_used :
220- warn (PABOT_WIHOUT_LAUNCH_ID_MSG , stacklevel = 2 )
221- logger .debug ('ReportPortal - Start Launch: {0}' . format ( launch .attributes ) )
199+ warn (PABOT_WITHOUT_LAUNCH_ID_MSG , stacklevel = 2 )
200+ logger .debug (f 'ReportPortal - Start Launch: { launch .robot_attributes } ' )
222201 self .service .start_launch (
223202 launch = launch ,
224203 mode = self .variables .mode ,
@@ -237,10 +216,10 @@ def start_suite(self, name: str, attributes: Dict, ts: Optional[Any] = None) ->
237216 if attributes ['id' ] == MAIN_SUITE_ID :
238217 self .start_launch (attributes , ts )
239218 if self .variables .pabot_used :
240- name += '.{0}' . format ( self .variables .pabot_pool_id )
241- logger .debug ('ReportPortal - Create global Suite: {0}' . format ( attributes ) )
219+ name = f' { name } . { self .variables .pabot_pool_id } '
220+ logger .debug (f 'ReportPortal - Create global Suite: { attributes } ' )
242221 else :
243- logger .debug ('ReportPortal - Start Suite: {0}' . format ( attributes ) )
222+ logger .debug (f 'ReportPortal - Start Suite: { attributes } ' )
244223 suite = Suite (name , attributes )
245224 suite .rp_parent_item_id = self .parent_id
246225 suite .rp_item_id = self .service .start_suite (suite = suite , ts = ts )
@@ -255,12 +234,11 @@ def end_suite(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None
255234 :param ts: Timestamp(used by the ResultVisitor)
256235 """
257236 suite = self ._remove_current_item ().update (attributes )
258- logger .debug ('ReportPortal - End Suite: {0}' . format ( suite .attributes ) )
237+ logger .debug (f 'ReportPortal - End Suite: { suite .robot_attributes } ' )
259238 self .service .finish_suite (suite = suite , ts = ts )
260239 if attributes ['id' ] == MAIN_SUITE_ID :
261- launch = Launch (self .variables .launch_name , attributes )
262- logger .debug (
263- msg = 'ReportPortal - End Launch: {0}' .format (attributes ))
240+ launch = Launch (self .variables .launch_name , attributes , None )
241+ logger .debug (msg = f'ReportPortal - End Launch: { attributes } ' )
264242 self .service .finish_launch (launch = launch , ts = ts )
265243
266244 @check_rp_enabled
@@ -275,9 +253,8 @@ def start_test(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> N
275253 # no 'source' parameter at this level for Robot versions < 4
276254 attributes = attributes .copy ()
277255 attributes ['source' ] = getattr (self .current_item , 'source' , None )
278- test = Test (name = name , attributes = attributes )
279- logger .debug ('ReportPortal - Start Test: {0}' .format (attributes ))
280- test .attributes = gen_attributes (self .variables .test_attributes + test .tags )
256+ test = Test (name = name , robot_attributes = attributes , test_attributes = self .variables .test_attributes )
257+ logger .debug (f'ReportPortal - Start Test: { attributes } ' )
281258 test .rp_parent_item_id = self .parent_id
282259 test .rp_item_id = self .service .start_test (test = test , ts = ts )
283260 self ._add_current_item (test )
@@ -291,13 +268,11 @@ def end_test(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None)
291268 :param ts: Timestamp(used by the ResultVisitor)
292269 """
293270 test = self .current_item .update (attributes )
294- test .attributes = gen_attributes (
295- self .variables .test_attributes + test .tags )
296271 if not test .critical and test .status == 'FAIL' :
297272 test .status = 'SKIP'
298273 if test .message :
299274 self .log_message ({'message' : test .message , 'level' : 'DEBUG' })
300- logger .debug ('ReportPortal - End Test: {0}' . format ( test .attributes ) )
275+ logger .debug (f 'ReportPortal - End Test: { test .robot_attributes } ' )
301276 self ._remove_current_item ()
302277 self .service .finish_test (test = test , ts = ts )
303278
@@ -309,9 +284,9 @@ def start_keyword(self, name: str, attributes: Dict, ts: Optional[Any] = None) -
309284 :param attributes: Dictionary passed by the Robot Framework
310285 :param ts: Timestamp(used by the ResultVisitor)
311286 """
312- kwd = Keyword (name = name , parent_type = self .current_item .type , attributes = attributes )
287+ kwd = Keyword (name = name , parent_type = self .current_item .type , robot_attributes = attributes )
313288 kwd .rp_parent_item_id = self .parent_id
314- logger .debug ('ReportPortal - Start Keyword: {0}' . format ( attributes ) )
289+ logger .debug (f 'ReportPortal - Start Keyword: { attributes } ' )
315290 kwd .rp_item_id = self .service .start_keyword (keyword = kwd , ts = ts )
316291 self ._add_current_item (kwd )
317292
@@ -324,7 +299,7 @@ def end_keyword(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = No
324299 :param ts: Timestamp(used by the ResultVisitor)
325300 """
326301 kwd = self ._remove_current_item ().update (attributes )
327- logger .debug ('ReportPortal - End Keyword: {0}' . format ( kwd .attributes ) )
302+ logger .debug (f 'ReportPortal - End Keyword: { kwd .robot_attributes } ' )
328303 self .service .finish_keyword (keyword = kwd , ts = ts )
329304
330305 def log_file (self , log_path : str ) -> None :
0 commit comments