From f6b5a61e98550887a480baada81d0a5ffa15777f Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 5 Dec 2023 13:52:12 +0300 Subject: [PATCH] Fixes #181 --- robotframework_reportportal/listener.py | 51 +++++++++---------------- robotframework_reportportal/service.py | 2 +- tests/__init__.py | 1 + tests/integration/test_variables.py | 18 ++++----- 4 files changed, 29 insertions(+), 43 deletions(-) diff --git a/robotframework_reportportal/listener.py b/robotframework_reportportal/listener.py index d68ec6a..17ea9b2 100644 --- a/robotframework_reportportal/listener.py +++ b/robotframework_reportportal/listener.py @@ -33,12 +33,14 @@ def check_rp_enabled(func): """Verify is RP is enabled in config.""" + @wraps(func) def wrap(*args, **kwargs): if args and isinstance(args[0], listener): if not args[0].service: return func(*args, **kwargs) + return wrap @@ -142,19 +144,15 @@ def start_launch(self, attributes: Dict, ts: Optional[Any] = None) -> None: launch = Launch(self.variables.launch_name, attributes) launch.attributes = gen_attributes(self.variables.launch_attributes) launch.doc = self.variables.launch_doc or launch.doc - if not self.variables.launch_id: - if self.variables.pabot_used: - warn(PABOT_WIHOUT_LAUNCH_ID_MSG, stacklevel=2) - logger.debug('ReportPortal - Start Launch: {0}'.format( - launch.attributes)) - self.service.start_launch( - launch=launch, - mode=self.variables.mode, - ts=ts, - rerun=self.variables.rerun, - rerun_of=self.variables.rerun_of) - else: - self.service.rp.launch_id = self.variables.launch_id + if self.variables.pabot_used: + warn(PABOT_WIHOUT_LAUNCH_ID_MSG, stacklevel=2) + logger.debug('ReportPortal - Start Launch: {0}'.format(launch.attributes)) + self.service.start_launch( + launch=launch, + mode=self.variables.mode, + ts=ts, + rerun=self.variables.rerun, + rerun_of=self.variables.rerun_of) @check_rp_enabled def start_suite(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> None: @@ -168,18 +166,13 @@ def start_suite(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> self.start_launch(attributes, ts) if self.variables.pabot_used: name += '.{0}'.format(self.variables.pabot_pool_id) - logger.debug( - 'ReportPortal - Create global Suite: {0}' - .format(attributes)) - suite = Suite(name, attributes) - suite.rp_item_id = self.service.start_suite(suite=suite, ts=ts) - self._add_current_item(suite) + logger.debug('ReportPortal - Create global Suite: {0}'.format(attributes)) else: logger.debug('ReportPortal - Start Suite: {0}'.format(attributes)) - suite = Suite(name, attributes) - suite.rp_parent_item_id = self.parent_id - suite.rp_item_id = self.service.start_suite(suite=suite, ts=ts) - self._add_current_item(suite) + suite = Suite(name, attributes) + suite.rp_parent_item_id = self.parent_id + suite.rp_item_id = self.service.start_suite(suite=suite, ts=ts) + self._add_current_item(suite) @check_rp_enabled def end_suite(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None) -> None: @@ -188,20 +181,14 @@ def end_suite(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None :param attributes: Dictionary passed by the Robot Framework :param ts: Timestamp(used by the ResultVisitor) """ + suite = self._remove_current_item().update(attributes) + logger.debug('ReportPortal - End Suite: {0}'.format(suite.attributes)) + self.service.finish_suite(suite=suite, ts=ts) if attributes['id'] == MAIN_SUITE_ID: - suite = self._remove_current_item().update(attributes) - logger.debug('ReportPortal - End Suite: {0}' - .format(suite.attributes)) - self.service.finish_suite(suite=suite, ts=ts) launch = Launch(self.variables.launch_name, attributes) logger.debug( msg='ReportPortal - End Launch: {0}'.format(attributes)) self.service.finish_launch(launch=launch, ts=ts) - else: - suite = self._remove_current_item().update(attributes) - logger.debug( - 'ReportPortal - End Suite: {0}'.format(suite.attributes)) - self.service.finish_suite(suite=suite, ts=ts) @check_rp_enabled def start_test(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> None: diff --git a/robotframework_reportportal/service.py b/robotframework_reportportal/service.py index 8aa11a8..0919d4e 100644 --- a/robotframework_reportportal/service.py +++ b/robotframework_reportportal/service.py @@ -96,7 +96,7 @@ def init_service(self, variables: Variables) -> None: verify_ssl=variables.verify_ssl, max_pool_size=variables.pool_size, log_batch_payload_size=variables.log_batch_payload_size, - launch_id=variables.launch_id, + launch_uuid=variables.launch_id, launch_uuid_print=variables.launch_uuid_print, print_output=variables.launch_uuid_print_output, http_timeout=variables.http_timeout diff --git a/tests/__init__.py b/tests/__init__.py index 7c58005..37c9923 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -15,3 +15,4 @@ """ REPORT_PORTAL_SERVICE = 'reportportal_client.RPClient' +REQUESTS_SERVICE = 'reportportal_client.client.requests.Session' diff --git a/tests/integration/test_variables.py b/tests/integration/test_variables.py index d6be789..124f79d 100644 --- a/tests/integration/test_variables.py +++ b/tests/integration/test_variables.py @@ -19,7 +19,7 @@ import pytest from reportportal_client import OutputType, RPClient, ThreadedRPClient, BatchedRPClient -from tests import REPORT_PORTAL_SERVICE +from tests import REPORT_PORTAL_SERVICE, REQUESTS_SERVICE from tests.helpers import utils @@ -38,8 +38,8 @@ def test_agent_pass_batch_payload_size_variable(mock_client_init): payload_variable] == payload_size -@mock.patch(REPORT_PORTAL_SERVICE) -def test_agent_pass_launch_uuid_variable(mock_client_init): +@mock.patch(REQUESTS_SERVICE) +def test_agent_pass_launch_uuid_variable(mock_requests_init): variables = utils.DEFAULT_VARIABLES.copy() test_launch_id = 'my_test_launch' variables['RP_LAUNCH_UUID'] = test_launch_id @@ -47,13 +47,11 @@ def test_agent_pass_launch_uuid_variable(mock_client_init): variables=variables) assert result == 0 # the test successfully passed - launch_id_variable = 'launch_id' - assert launch_id_variable in mock_client_init.call_args_list[0][1] - assert mock_client_init.call_args_list[0][1][ - launch_id_variable] == test_launch_id - - mock_client = mock_client_init.return_value - assert mock_client.start_launch.call_count == 0 + mock_requests = mock_requests_init.return_value + assert mock_requests.post.call_count == 3 + suite_start = mock_requests.post.call_args_list[0] + assert suite_start[0][0].endswith('/item') + assert suite_start[1]['json']['launchUuid'] == test_launch_id @pytest.mark.parametrize('variable, warn_num',