Skip to content

Commit 984973e

Browse files
authored
Merge pull request #212 from reportportal/develop
Release
2 parents 2b468c8 + 5c45d70 commit 984973e

File tree

4 files changed

+74
-10
lines changed

4 files changed

+74
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Added
5+
- `RP_DEBUG_MODE` configuration variable, by @HardNorth
6+
7+
## [5.6.3]
48
### Removed
59
- Logging in the `listener.__post_log_message` method, to avoid logging the same message recursively, by @HardNorth
610

robotframework_reportportal/service.py

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ class RobotService:
5151
agent_name: str
5252
agent_version: str
5353
rp: Optional[RP]
54+
debug: bool
5455

5556
def __init__(self) -> None:
5657
"""Initialize service attributes."""
5758
self.agent_name = "robotframework-reportportal"
5859
self.agent_version = get_package_version(self.agent_name)
5960
self.rp = None
61+
self.debug = False
6062

6163
def _get_launch_attributes(self, cmd_attrs: list) -> list:
6264
"""Generate launch attributes including both system and user ones.
@@ -74,6 +76,7 @@ def init_service(self, variables: Variables) -> None:
7476
:param variables: ReportPortal variables
7577
"""
7678
if self.rp is None:
79+
self.debug = variables.debug_mode
7780
logger.debug(
7881
f"ReportPortal - Init service: endpoint={variables.endpoint}, "
7982
f"project={variables.project}, api_key={variables.api_key}"
@@ -129,7 +132,13 @@ def start_launch(
129132
"start_time": ts or to_epoch(launch.start_time) or timestamp(),
130133
}
131134
logger.debug("ReportPortal - Start launch: request_body={0}".format(sl_pt))
132-
return self.rp.start_launch(**sl_pt)
135+
try:
136+
return self.rp.start_launch(**sl_pt)
137+
except Exception as e:
138+
if self.debug:
139+
logger.error(f"Unable to start launch: {e}")
140+
logger.exception(e)
141+
raise e
133142

134143
def finish_launch(self, launch: Launch, ts: Optional[str] = None) -> None:
135144
"""Finish started launch.
@@ -139,7 +148,13 @@ def finish_launch(self, launch: Launch, ts: Optional[str] = None) -> None:
139148
"""
140149
fl_rq = {"end_time": ts or to_epoch(launch.end_time) or timestamp(), "status": STATUS_MAPPING[launch.status]}
141150
logger.debug("ReportPortal - Finish launch: request_body={0}".format(fl_rq))
142-
self.rp.finish_launch(**fl_rq)
151+
try:
152+
self.rp.finish_launch(**fl_rq)
153+
except Exception as e:
154+
if self.debug:
155+
logger.error(f"Unable to finish launch: {e}")
156+
logger.exception(e)
157+
raise e
143158

144159
def start_suite(self, suite: Suite, ts: Optional[str] = None) -> Optional[str]:
145160
"""Call start_test method of the common client.
@@ -157,7 +172,13 @@ def start_suite(self, suite: Suite, ts: Optional[str] = None) -> Optional[str]:
157172
"start_time": ts or to_epoch(suite.start_time) or timestamp(),
158173
}
159174
logger.debug("ReportPortal - Start suite: request_body={0}".format(start_rq))
160-
return self.rp.start_test_item(**start_rq)
175+
try:
176+
return self.rp.start_test_item(**start_rq)
177+
except Exception as e:
178+
if self.debug:
179+
logger.error(f"Unable to start suite: {e}")
180+
logger.exception(e)
181+
raise e
161182

162183
def finish_suite(self, suite: Suite, issue: Optional[str] = None, ts: Optional[str] = None) -> None:
163184
"""Finish started suite.
@@ -173,7 +194,13 @@ def finish_suite(self, suite: Suite, issue: Optional[str] = None, ts: Optional[s
173194
"status": STATUS_MAPPING[suite.status],
174195
}
175196
logger.debug("ReportPortal - Finish suite: request_body={0}".format(fta_rq))
176-
self.rp.finish_test_item(**fta_rq)
197+
try:
198+
self.rp.finish_test_item(**fta_rq)
199+
except Exception as e:
200+
if self.debug:
201+
logger.error(f"Unable to finish suite: {e}")
202+
logger.exception(e)
203+
raise e
177204

178205
def start_test(self, test: Test, ts: Optional[str] = None):
179206
"""Call start_test method of the common client.
@@ -195,7 +222,13 @@ def start_test(self, test: Test, ts: Optional[str] = None):
195222
"test_case_id": test.test_case_id,
196223
}
197224
logger.debug("ReportPortal - Start test: request_body={0}".format(start_rq))
198-
return self.rp.start_test_item(**start_rq)
225+
try:
226+
return self.rp.start_test_item(**start_rq)
227+
except Exception as e:
228+
if self.debug:
229+
logger.error(f"Unable to start test: {e}")
230+
logger.exception(e)
231+
raise e
199232

200233
def finish_test(self, test: Test, issue: Optional[str] = None, ts: Optional[str] = None):
201234
"""Finish started test case.
@@ -224,7 +257,13 @@ def finish_test(self, test: Test, issue: Optional[str] = None, ts: Optional[str]
224257
if description:
225258
fta_rq["description"] = description
226259
logger.debug("ReportPortal - Finish test: request_body={0}".format(fta_rq))
227-
self.rp.finish_test_item(**fta_rq)
260+
try:
261+
self.rp.finish_test_item(**fta_rq)
262+
except Exception as e:
263+
if self.debug:
264+
logger.error(f"Unable to finish test: {e}")
265+
logger.exception(e)
266+
raise e
228267

229268
def start_keyword(self, keyword: Keyword, ts: Optional[str] = None):
230269
"""Call start_test method of the common client.
@@ -243,7 +282,13 @@ def start_keyword(self, keyword: Keyword, ts: Optional[str] = None):
243282
if keyword.rp_item_id:
244283
start_rq["uuid"] = keyword.rp_item_id
245284
logger.debug("ReportPortal - Start keyword: request_body={0}".format(start_rq))
246-
return self.rp.start_test_item(**start_rq)
285+
try:
286+
return self.rp.start_test_item(**start_rq)
287+
except Exception as e:
288+
if self.debug:
289+
logger.error(f"Unable to start keyword: {e}")
290+
logger.exception(e)
291+
raise e
247292

248293
def finish_keyword(self, keyword: Keyword, issue: Optional[str] = None, ts: Optional[str] = None):
249294
"""Finish started keyword item.
@@ -259,7 +304,13 @@ def finish_keyword(self, keyword: Keyword, issue: Optional[str] = None, ts: Opti
259304
"status": STATUS_MAPPING[keyword.status],
260305
}
261306
logger.debug("ReportPortal - Finish keyword: request_body={0}".format(fta_rq))
262-
self.rp.finish_test_item(**fta_rq)
307+
try:
308+
self.rp.finish_test_item(**fta_rq)
309+
except Exception as e:
310+
if self.debug:
311+
logger.error(f"Unable to finish keyword: {e}")
312+
logger.exception(e)
313+
raise e
263314

264315
def log(self, message: LogMessage, ts: Optional[str] = None):
265316
"""Send log message to ReportPortal.
@@ -274,4 +325,10 @@ def log(self, message: LogMessage, ts: Optional[str] = None):
274325
"message": message.message,
275326
"time": ts or to_epoch(message.timestamp) or timestamp(),
276327
}
277-
self.rp.log(**sl_rq)
328+
try:
329+
self.rp.log(**sl_rq)
330+
except Exception as e:
331+
if self.debug:
332+
logger.error(f"Unable to send log message: {e}")
333+
logger.exception(e)
334+
raise e

robotframework_reportportal/variables.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Variables:
6969
http_timeout: Optional[Union[Tuple[float, float], float]]
7070
remove_keywords: bool
7171
flatten_keywords: bool
72+
debug_mode: bool
7273

7374
def __init__(self) -> None:
7475
"""Initialize instance attributes."""
@@ -135,6 +136,8 @@ def __init__(self) -> None:
135136
stacklevel=2,
136137
)
137138

139+
self.debug_mode = to_bool(get_variable("RP_DEBUG_MODE", default="False"))
140+
138141
cond = (self.endpoint, self.launch_name, self.project, self.api_key)
139142
self.enabled = all(cond)
140143
if not self.enabled:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from setuptools import setup
2020

21-
__version__ = "5.6.3"
21+
__version__ = "5.6.4"
2222

2323

2424
def read_file(fname):

0 commit comments

Comments
 (0)