20
20
import re
21
21
from functools import wraps
22
22
from mimetypes import guess_type
23
- from types import MappingProxyType
24
23
from typing import Optional , Dict , Union , Any
25
24
from warnings import warn
26
25
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
28
27
29
28
from .model import Keyword , Launch , Test , LogMessage , Suite
30
29
from .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
32
31
from .variables import Variables
33
32
34
33
logger = logging .getLogger (__name__ )
35
34
VARIABLE_PATTERN = r'^\s*\${[^}]*}\s*=\s*'
36
35
TRUNCATION_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
- })
55
36
56
37
57
38
def _unescape (binary_string : str , stop_at : int = - 1 ):
@@ -106,9 +87,9 @@ def wrap(*args, **kwargs):
106
87
class listener :
107
88
"""Robot Framework listener interface for reporting to ReportPortal."""
108
89
109
- _items : LifoQueue = ...
110
- _service : Optional [RobotService ] = ...
111
- _variables : Optional [Variables ] = ...
90
+ _items : LifoQueue
91
+ _service : Optional [RobotService ]
92
+ _variables : Optional [Variables ]
112
93
ROBOT_LISTENER_API_VERSION = 2
113
94
114
95
def __init__ (self ) -> None :
@@ -165,7 +146,7 @@ def log_message(self, message: Dict) -> None:
165
146
msg .message = (f'Binary data of type "{ content_type } " logging skipped, as it was processed as text and'
166
147
' hence corrupted.' )
167
148
msg .level = 'WARN'
168
- logger .debug ('ReportPortal - Log Message: {0}' . format ( message ) )
149
+ logger .debug (f 'ReportPortal - Log Message: { message } ' )
169
150
self .service .log (message = msg )
170
151
171
152
@check_rp_enabled
@@ -182,8 +163,7 @@ def log_message_with_image(self, msg: Dict, image: str):
182
163
'data' : fh .read (),
183
164
'mime' : guess_type (image )[0 ] or 'application/octet-stream'
184
165
}
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 } ' )
187
167
self .service .log (message = mes )
188
168
189
169
@property
@@ -207,18 +187,17 @@ def variables(self) -> Variables:
207
187
return self ._variables
208
188
209
189
@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 :
211
191
"""Start a new launch at the ReportPortal.
212
192
213
193
:param attributes: Dictionary passed by the Robot Framework
214
194
:param ts: Timestamp(used by the ResultVisitor)
215
195
"""
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 )
218
197
launch .doc = self .variables .launch_doc or launch .doc
219
198
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 } ' )
222
201
self .service .start_launch (
223
202
launch = launch ,
224
203
mode = self .variables .mode ,
@@ -237,10 +216,10 @@ def start_suite(self, name: str, attributes: Dict, ts: Optional[Any] = None) ->
237
216
if attributes ['id' ] == MAIN_SUITE_ID :
238
217
self .start_launch (attributes , ts )
239
218
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 } ' )
242
221
else :
243
- logger .debug ('ReportPortal - Start Suite: {0}' . format ( attributes ) )
222
+ logger .debug (f 'ReportPortal - Start Suite: { attributes } ' )
244
223
suite = Suite (name , attributes )
245
224
suite .rp_parent_item_id = self .parent_id
246
225
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
255
234
:param ts: Timestamp(used by the ResultVisitor)
256
235
"""
257
236
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 } ' )
259
238
self .service .finish_suite (suite = suite , ts = ts )
260
239
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 } ' )
264
242
self .service .finish_launch (launch = launch , ts = ts )
265
243
266
244
@check_rp_enabled
@@ -275,9 +253,8 @@ def start_test(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> N
275
253
# no 'source' parameter at this level for Robot versions < 4
276
254
attributes = attributes .copy ()
277
255
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 } ' )
281
258
test .rp_parent_item_id = self .parent_id
282
259
test .rp_item_id = self .service .start_test (test = test , ts = ts )
283
260
self ._add_current_item (test )
@@ -291,13 +268,11 @@ def end_test(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None)
291
268
:param ts: Timestamp(used by the ResultVisitor)
292
269
"""
293
270
test = self .current_item .update (attributes )
294
- test .attributes = gen_attributes (
295
- self .variables .test_attributes + test .tags )
296
271
if not test .critical and test .status == 'FAIL' :
297
272
test .status = 'SKIP'
298
273
if test .message :
299
274
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 } ' )
301
276
self ._remove_current_item ()
302
277
self .service .finish_test (test = test , ts = ts )
303
278
@@ -309,9 +284,9 @@ def start_keyword(self, name: str, attributes: Dict, ts: Optional[Any] = None) -
309
284
:param attributes: Dictionary passed by the Robot Framework
310
285
:param ts: Timestamp(used by the ResultVisitor)
311
286
"""
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 )
313
288
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 } ' )
315
290
kwd .rp_item_id = self .service .start_keyword (keyword = kwd , ts = ts )
316
291
self ._add_current_item (kwd )
317
292
@@ -324,7 +299,7 @@ def end_keyword(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = No
324
299
:param ts: Timestamp(used by the ResultVisitor)
325
300
"""
326
301
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 } ' )
328
303
self .service .finish_keyword (keyword = kwd , ts = ts )
329
304
330
305
def log_file (self , log_path : str ) -> None :
0 commit comments