16
16
17
17
import logging
18
18
import os
19
+ from functools import wraps
19
20
from mimetypes import guess_type
20
21
21
22
from reportportal_client .helpers import gen_attributes
29
30
logger = logging .getLogger (__name__ )
30
31
31
32
33
+ def check_rp_enabled (func ):
34
+ """Verify is RP is enabled in config."""
35
+ @wraps (func )
36
+ def wrap (* args , ** kwargs ):
37
+ if args and isinstance (args [0 ], listener ):
38
+ if not args [0 ].service :
39
+ return
40
+ func (* args , ** kwargs )
41
+ return wrap
42
+
43
+
32
44
class listener (object ):
33
45
"""Robot Framework listener interface for reporting to Report Portal."""
34
46
@@ -64,6 +76,7 @@ def current_item(self):
64
76
if self ._items :
65
77
return self ._items [- 1 ]
66
78
79
+ @check_rp_enabled
67
80
def log_message (self , message ):
68
81
"""Send log message to the Report Portal.
69
82
@@ -73,6 +86,7 @@ def log_message(self, message):
73
86
logger .debug ('ReportPortal - Log Message: {0}' .format (message ))
74
87
self .service .log (message = msg )
75
88
89
+ @check_rp_enabled
76
90
def log_message_with_image (self , msg , image ):
77
91
"""Send log message to the Report Portal.
78
92
@@ -98,12 +112,12 @@ def parent_id(self):
98
112
@property
99
113
def service (self ):
100
114
"""Initialize instance of the RobotService."""
101
- if self ._service is None :
115
+ if self .variables . enabled and self . _service is None :
102
116
self ._service = RobotService ()
103
117
self ._service .init_service (
104
118
endpoint = self .variables .endpoint ,
105
119
project = self .variables .project ,
106
- uuid = self .variables .uuid ,
120
+ api_key = self .variables .api_key ,
107
121
log_batch_size = self .variables .log_batch_size ,
108
122
pool_size = self .variables .pool_size ,
109
123
skipped_issue = self .variables .skipped_issue ,
@@ -120,6 +134,7 @@ def variables(self):
120
134
self ._variables = Variables ()
121
135
return self ._variables
122
136
137
+ @check_rp_enabled
123
138
def start_launch (self , attributes , ts = None ):
124
139
"""Start a new launch at the Report Portal.
125
140
@@ -143,6 +158,7 @@ def start_launch(self, attributes, ts=None):
143
158
else :
144
159
self .service .rp .launch_id = self .variables .launch_id
145
160
161
+ @check_rp_enabled
146
162
def start_suite (self , name , attributes , ts = None ):
147
163
"""Start a new test suite at the Report Portal.
148
164
@@ -167,6 +183,7 @@ def start_suite(self, name, attributes, ts=None):
167
183
suite .rp_item_id = self .service .start_suite (suite = suite , ts = ts )
168
184
self ._items .append (suite )
169
185
186
+ @check_rp_enabled
170
187
def end_suite (self , _ , attributes , ts = None ):
171
188
"""Finish started test suite at the Report Portal.
172
189
@@ -188,6 +205,7 @@ def end_suite(self, _, attributes, ts=None):
188
205
'ReportPortal - End Suite: {0}' .format (suite .attributes ))
189
206
self .service .finish_suite (suite = suite , ts = ts )
190
207
208
+ @check_rp_enabled
191
209
def start_test (self , name , attributes , ts = None ):
192
210
"""Start a new test case at the Report Portal.
193
211
@@ -207,6 +225,7 @@ def start_test(self, name, attributes, ts=None):
207
225
test .rp_item_id = self .service .start_test (test = test , ts = ts )
208
226
self ._items .append (test )
209
227
228
+ @check_rp_enabled
210
229
def end_test (self , _ , attributes , ts = None ):
211
230
"""Finish started test case at the Report Portal.
212
231
@@ -224,6 +243,7 @@ def end_test(self, _, attributes, ts=None):
224
243
self ._finish_current_item ()
225
244
self .service .finish_test (test = test , ts = ts )
226
245
246
+ @check_rp_enabled
227
247
def start_keyword (self , name , attributes , ts = None ):
228
248
"""Start a new keyword(test step) at the Report Portal.
229
249
@@ -238,6 +258,7 @@ def start_keyword(self, name, attributes, ts=None):
238
258
kwd .rp_item_id = self .service .start_keyword (keyword = kwd , ts = ts )
239
259
self ._items .append (kwd )
240
260
261
+ @check_rp_enabled
241
262
def end_keyword (self , _ , attributes , ts = None ):
242
263
"""Finish started keyword at the Report Portal.
243
264
@@ -275,6 +296,7 @@ def xunit_file(self, xunit_path):
275
296
message = {'message' : 'XUnit result file' , 'level' : 'INFO' }
276
297
self .log_message_with_image (message , xunit_path )
277
298
299
+ @check_rp_enabled
278
300
def close (self ):
279
301
"""Call service terminate when the whole test execution is done."""
280
302
self .service .terminate_service ()
0 commit comments