Skip to content

Commit

Permalink
Fixes #181
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Dec 5, 2023
1 parent 5515f07 commit f6b5a61
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 43 deletions.
51 changes: 19 additions & 32 deletions robotframework_reportportal/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion robotframework_reportportal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
"""

REPORT_PORTAL_SERVICE = 'reportportal_client.RPClient'
REQUESTS_SERVICE = 'reportportal_client.client.requests.Session'
18 changes: 8 additions & 10 deletions tests/integration/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -38,22 +38,20 @@ 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
result = utils.run_robot_tests(['examples/simple.robot'],
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',
Expand Down

0 comments on commit f6b5a61

Please sign in to comment.