Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
### Added
- `RP_DEBUG_MODE` configuration variable, by @HardNorth

## [5.6.3]
### Removed
- Logging in the `listener.__post_log_message` method, to avoid logging the same message recursively, by @HardNorth

Expand Down
75 changes: 66 additions & 9 deletions robotframework_reportportal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ class RobotService:
agent_name: str
agent_version: str
rp: Optional[RP]
debug: bool

def __init__(self) -> None:
"""Initialize service attributes."""
self.agent_name = "robotframework-reportportal"
self.agent_version = get_package_version(self.agent_name)
self.rp = None
self.debug = False

def _get_launch_attributes(self, cmd_attrs: list) -> list:
"""Generate launch attributes including both system and user ones.
Expand All @@ -74,6 +76,7 @@ def init_service(self, variables: Variables) -> None:
:param variables: ReportPortal variables
"""
if self.rp is None:
self.debug = variables.debug_mode
logger.debug(
f"ReportPortal - Init service: endpoint={variables.endpoint}, "
f"project={variables.project}, api_key={variables.api_key}"
Expand Down Expand Up @@ -129,7 +132,13 @@ def start_launch(
"start_time": ts or to_epoch(launch.start_time) or timestamp(),
}
logger.debug("ReportPortal - Start launch: request_body={0}".format(sl_pt))
return self.rp.start_launch(**sl_pt)
try:
return self.rp.start_launch(**sl_pt)
except Exception as e:
if self.debug:
logger.error(f"Unable to start launch: {e}")
logger.exception(e)
raise e

def finish_launch(self, launch: Launch, ts: Optional[str] = None) -> None:
"""Finish started launch.
Expand All @@ -139,7 +148,13 @@ def finish_launch(self, launch: Launch, ts: Optional[str] = None) -> None:
"""
fl_rq = {"end_time": ts or to_epoch(launch.end_time) or timestamp(), "status": STATUS_MAPPING[launch.status]}
logger.debug("ReportPortal - Finish launch: request_body={0}".format(fl_rq))
self.rp.finish_launch(**fl_rq)
try:
self.rp.finish_launch(**fl_rq)
except Exception as e:
if self.debug:
logger.error(f"Unable to finish launch: {e}")
logger.exception(e)
raise e

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

def finish_suite(self, suite: Suite, issue: Optional[str] = None, ts: Optional[str] = None) -> None:
"""Finish started suite.
Expand All @@ -173,7 +194,13 @@ def finish_suite(self, suite: Suite, issue: Optional[str] = None, ts: Optional[s
"status": STATUS_MAPPING[suite.status],
}
logger.debug("ReportPortal - Finish suite: request_body={0}".format(fta_rq))
self.rp.finish_test_item(**fta_rq)
try:
self.rp.finish_test_item(**fta_rq)
except Exception as e:
if self.debug:
logger.error(f"Unable to finish suite: {e}")
logger.exception(e)
raise e

def start_test(self, test: Test, ts: Optional[str] = None):
"""Call start_test method of the common client.
Expand All @@ -195,7 +222,13 @@ def start_test(self, test: Test, ts: Optional[str] = None):
"test_case_id": test.test_case_id,
}
logger.debug("ReportPortal - Start test: request_body={0}".format(start_rq))
return self.rp.start_test_item(**start_rq)
try:
return self.rp.start_test_item(**start_rq)
except Exception as e:
if self.debug:
logger.error(f"Unable to start test: {e}")
logger.exception(e)
raise e

def finish_test(self, test: Test, issue: Optional[str] = None, ts: Optional[str] = None):
"""Finish started test case.
Expand Down Expand Up @@ -224,7 +257,13 @@ def finish_test(self, test: Test, issue: Optional[str] = None, ts: Optional[str]
if description:
fta_rq["description"] = description
logger.debug("ReportPortal - Finish test: request_body={0}".format(fta_rq))
self.rp.finish_test_item(**fta_rq)
try:
self.rp.finish_test_item(**fta_rq)
except Exception as e:
if self.debug:
logger.error(f"Unable to finish test: {e}")
logger.exception(e)
raise e

def start_keyword(self, keyword: Keyword, ts: Optional[str] = None):
"""Call start_test method of the common client.
Expand All @@ -243,7 +282,13 @@ def start_keyword(self, keyword: Keyword, ts: Optional[str] = None):
if keyword.rp_item_id:
start_rq["uuid"] = keyword.rp_item_id
logger.debug("ReportPortal - Start keyword: request_body={0}".format(start_rq))
return self.rp.start_test_item(**start_rq)
try:
return self.rp.start_test_item(**start_rq)
except Exception as e:
if self.debug:
logger.error(f"Unable to start keyword: {e}")
logger.exception(e)
raise e

def finish_keyword(self, keyword: Keyword, issue: Optional[str] = None, ts: Optional[str] = None):
"""Finish started keyword item.
Expand All @@ -259,7 +304,13 @@ def finish_keyword(self, keyword: Keyword, issue: Optional[str] = None, ts: Opti
"status": STATUS_MAPPING[keyword.status],
}
logger.debug("ReportPortal - Finish keyword: request_body={0}".format(fta_rq))
self.rp.finish_test_item(**fta_rq)
try:
self.rp.finish_test_item(**fta_rq)
except Exception as e:
if self.debug:
logger.error(f"Unable to finish keyword: {e}")
logger.exception(e)
raise e

def log(self, message: LogMessage, ts: Optional[str] = None):
"""Send log message to ReportPortal.
Expand All @@ -274,4 +325,10 @@ def log(self, message: LogMessage, ts: Optional[str] = None):
"message": message.message,
"time": ts or to_epoch(message.timestamp) or timestamp(),
}
self.rp.log(**sl_rq)
try:
self.rp.log(**sl_rq)
except Exception as e:
if self.debug:
logger.error(f"Unable to send log message: {e}")
logger.exception(e)
raise e
3 changes: 3 additions & 0 deletions robotframework_reportportal/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Variables:
http_timeout: Optional[Union[Tuple[float, float], float]]
remove_keywords: bool
flatten_keywords: bool
debug_mode: bool

def __init__(self) -> None:
"""Initialize instance attributes."""
Expand Down Expand Up @@ -135,6 +136,8 @@ def __init__(self) -> None:
stacklevel=2,
)

self.debug_mode = to_bool(get_variable("RP_DEBUG_MODE", default="False"))

cond = (self.endpoint, self.launch_name, self.project, self.api_key)
self.enabled = all(cond)
if not self.enabled:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from setuptools import setup

__version__ = "5.6.3"
__version__ = "5.6.4"


def read_file(fname):
Expand Down