Skip to content

Commit 5f5cadf

Browse files
committed
rp_launch_id` property handling moved completely on Client side, by @HardNorth
1 parent c3c4e45 commit 5f5cadf

File tree

5 files changed

+29
-51
lines changed

5 files changed

+29
-51
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44
### Changed
55
- Client version updated on [5.5.4](https://github.com/reportportal/client-Python/releases/tag/5.5.4), by @HardNorth
6+
- `rp_launch_id` property handling moved completely on Client side, by @HardNorth
67

78
## [5.3.0]
89
### Added

pytest_reportportal/plugin.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def pytest_configure_node(node):
5353
if not node.config._rp_enabled:
5454
# Stop now if the plugin is not properly configured
5555
return
56-
node.workerinput['py_test_service'] = pickle.dumps(
57-
node.config.py_test_service)
56+
node.workerinput['py_test_service'] = pickle.dumps(node.config.py_test_service)
5857

5958

6059
def is_control(config):
@@ -102,7 +101,7 @@ def pytest_sessionstart(session):
102101
config._rp_enabled = False
103102
return
104103

105-
if is_control(config) and not config._reporter_config.rp_launch_id:
104+
if is_control(config):
106105
config.py_test_service.start_launch()
107106
if config.pluginmanager.hasplugin('xdist') \
108107
or config.pluginmanager.hasplugin('pytest-parallel'):
@@ -137,8 +136,7 @@ def pytest_sessionfinish(session):
137136
return
138137

139138
config.py_test_service.finish_suites()
140-
if is_control(config) \
141-
and not config._reporter_config.rp_launch_id:
139+
if is_control(config):
142140
config.py_test_service.finish_launch()
143141

144142
config.py_test_service.stop()
@@ -224,8 +222,7 @@ def pytest_configure(config):
224222
config.py_test_service = PyTestServiceClass(agent_config)
225223
else:
226224
# noinspection PyUnresolvedReferences
227-
config.py_test_service = pickle.loads(
228-
config.workerinput['py_test_service'])
225+
config.py_test_service = pickle.loads(config.workerinput['py_test_service'])
229226

230227

231228
# noinspection PyProtectedMember

pytest_reportportal/service.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ def _get_launch_attributes(self, ini_attrs):
184184

185185
def _build_start_launch_rq(self):
186186
rp_launch_attributes = self._config.rp_launch_attributes
187-
attributes = gen_attributes(rp_launch_attributes) \
188-
if rp_launch_attributes else None
187+
attributes = gen_attributes(rp_launch_attributes) if rp_launch_attributes else None
189188

190189
start_rq = {
191190
'attributes': self._get_launch_attributes(attributes),
@@ -909,7 +908,7 @@ def start(self) -> None:
909908
log_batch_size=self._config.rp_log_batch_size,
910909
retries=self._config.rp_api_retries,
911910
verify_ssl=self._config.rp_verify_ssl,
912-
launch_id=launch_id,
911+
launch_uuid=launch_id,
913912
log_batch_payload_size=self._config.rp_log_batch_payload_size,
914913
launch_uuid_print=self._config.rp_launch_uuid_print,
915914
print_output=self._config.rp_launch_uuid_print_output,

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
"""This package contains tests for the project."""
1515

1616
REPORT_PORTAL_SERVICE = 'reportportal_client.RPClient'
17+
REQUESTS_SERVICE = 'reportportal_client.client.requests.Session'

tests/integration/test_config_handling.py

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,29 @@
2222
from reportportal_client import OutputType
2323

2424
from examples.test_rp_logging import LOG_MESSAGE
25-
from tests import REPORT_PORTAL_SERVICE
25+
from tests import REPORT_PORTAL_SERVICE, REQUESTS_SERVICE
2626
from tests.helpers import utils
2727

2828
TEST_LAUNCH_ID = 'test_launch_id'
2929

3030

31-
@mock.patch(REPORT_PORTAL_SERVICE)
32-
def test_rp_launch_id(mock_client_init):
31+
@mock.patch(REQUESTS_SERVICE)
32+
def test_rp_launch_id(mock_requests_init):
3333
"""Verify that RP plugin does not start/stop launch if 'rp_launch_id' set.
3434
35-
:param mock_client_init: Pytest fixture
35+
:param mock_requests_init: mocked requests lib
3636
"""
3737
variables = dict()
3838
variables['rp_launch_id'] = TEST_LAUNCH_ID
3939
variables.update(utils.DEFAULT_VARIABLES.items())
40-
result = utils.run_pytest_tests(tests=['examples/test_simple.py'],
41-
variables=variables)
42-
40+
result = utils.run_pytest_tests(tests=['examples/test_simple.py'], variables=variables)
4341
assert int(result) == 0, 'Exit code should be 0 (no errors)'
4442

45-
expect(
46-
mock_client_init.call_args_list[0][1]['launch_id'] == TEST_LAUNCH_ID)
47-
48-
mock_client = mock_client_init.return_value
49-
expect(mock_client.start_launch.call_count == 0,
50-
'"start_launch" method was called')
51-
expect(mock_client.finish_launch.call_count == 0,
52-
'"finish_launch" method was called')
53-
54-
start_call_args = mock_client.start_test_item.call_args_list
55-
finish_call_args = mock_client.finish_test_item.call_args_list
56-
57-
expect(len(start_call_args) == len(finish_call_args))
58-
assert_expectations()
43+
mock_requests = mock_requests_init.return_value
44+
assert mock_requests.post.call_count == 1
45+
item_start = mock_requests.post.call_args_list[0]
46+
assert item_start[0][0].endswith('/item')
47+
assert item_start[1]['json']['launchUuid'] == TEST_LAUNCH_ID
5948

6049

6150
@mock.patch(REPORT_PORTAL_SERVICE)
@@ -68,8 +57,7 @@ def test_rp_parent_item_id(mock_client_init):
6857
variables = dict()
6958
variables['rp_parent_item_id'] = parent_id
7059
variables.update(utils.DEFAULT_VARIABLES.items())
71-
result = utils.run_pytest_tests(tests=['examples/test_simple.py'],
72-
variables=variables)
60+
result = utils.run_pytest_tests(tests=['examples/test_simple.py'], variables=variables)
7361

7462
assert int(result) == 0, 'Exit code should be 0 (no errors)'
7563

@@ -87,34 +75,26 @@ def test_rp_parent_item_id(mock_client_init):
8775
assert_expectations()
8876

8977

90-
@mock.patch(REPORT_PORTAL_SERVICE)
91-
def test_rp_parent_item_id_and_rp_launch_id(mock_client_init):
78+
@mock.patch(REQUESTS_SERVICE)
79+
def test_rp_parent_item_id_and_rp_launch_id(mock_requests_init):
9280
"""Verify RP handles both conf props 'rp_parent_item_id' & 'rp_launch_id'.
9381
94-
:param mock_client_init: Pytest fixture
82+
:param mock_requests_init: mocked requests lib
9583
"""
9684
parent_id = "parent_id"
9785
variables = dict()
9886
variables['rp_parent_item_id'] = parent_id
99-
variables['rp_launch_id'] = "test_launch_id"
87+
variables['rp_launch_id'] = TEST_LAUNCH_ID
10088
variables.update(utils.DEFAULT_VARIABLES.items())
101-
result = utils.run_pytest_tests(tests=['examples/test_simple.py'],
102-
variables=variables)
103-
89+
result = utils.run_pytest_tests(tests=['examples/test_simple.py'],variables=variables)
10490
assert int(result) == 0, 'Exit code should be 0 (no errors)'
10591

106-
mock_client = mock_client_init.return_value
107-
expect(mock_client.start_launch.call_count == 0,
108-
'"start_launch" method was called')
109-
expect(mock_client.finish_launch.call_count == 0,
110-
'"finish_launch" method was called')
111-
112-
start_call_args = mock_client.start_test_item.call_args_list
113-
finish_call_args = mock_client.finish_test_item.call_args_list
92+
mock_requests = mock_requests_init.return_value
93+
assert mock_requests.post.call_count == 1
94+
item_start = mock_requests.post.call_args_list[0]
95+
assert item_start[0][0].endswith(f'/item/{parent_id}')
96+
assert item_start[1]['json']['launchUuid'] == TEST_LAUNCH_ID
11497

115-
expect(len(start_call_args) == len(finish_call_args))
116-
expect(start_call_args[0][1]["parent_item_id"] == parent_id)
117-
assert_expectations()
11898

11999

120100
@mock.patch(REPORT_PORTAL_SERVICE)

0 commit comments

Comments
 (0)