Skip to content

Commit 0154506

Browse files
authored
Merge pull request #356 from reportportal/develop
Release
2 parents 50676ac + f524b24 commit 0154506

File tree

10 files changed

+49
-73
lines changed

10 files changed

+49
-73
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Changed
5+
- 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
7+
8+
## [5.3.0]
49
### Added
5-
- `RP_CLIENT_TYPE` configuration variable, by @HardNorth
6-
- `RP_CONNECT_TIMEOUT` and `RP_READ_TIMEOUT` configuration variables, by @HardNorth
10+
- `rp_client_type` configuration variable, by @HardNorth
11+
- `rp_connect_timeout` and `rp_read_timeout` configuration variables, by @HardNorth
712
### Changed
813
- Client version updated on [5.5.2](https://github.com/reportportal/client-Python/releases/tag/5.5.2), by @HardNorth
914

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ agent-python-pytest
1111
.. image:: https://github.com/reportportal/agent-python-pytest/actions/workflows/tests.yml/badge.svg
1212
:target: https://github.com/reportportal/agent-python-pytest/actions/workflows/tests.yml
1313
:alt: Test status
14-
.. image:: https://codecov.io/gh/reportportal/agent-python-pytest/branch/master/graph/badge.svg
14+
.. image:: https://codecov.io/gh/reportportal/agent-python-pytest/branch/develop/graph/badge.svg
1515
:target: https://codecov.io/gh/reportportal/agent-python-pytest
1616
:alt: Test coverage
1717
.. image:: https://slack.epmrpp.reportportal.io/badge.svg

pytest_reportportal/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
get_actual_log_level
3131

3232

33-
class AgentConfig(object):
33+
class AgentConfig:
3434
"""Storage for the RP agent initialization attributes."""
3535

3636
rp_client_type: Optional[ClientType]

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,

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dill>=0.3.6
22
pytest>=3.8.0
3-
reportportal-client~=5.5.2
3+
reportportal-client~=5.5.4
44
aenum>=3.1.0
55
requests>=2.28.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from setuptools import setup
1919

2020

21-
__version__ = '5.3.0'
21+
__version__ = '5.3.1'
2222

2323

2424
def read_file(fname):

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 & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,33 @@
1717
from unittest import mock
1818

1919
import pytest
20-
2120
from delayed_assert import expect, assert_expectations
2221
from reportportal_client import OutputType
2322

2423
from examples.test_rp_logging import LOG_MESSAGE
25-
from tests import REPORT_PORTAL_SERVICE
24+
from tests import REPORT_PORTAL_SERVICE, REQUESTS_SERVICE
2625
from tests.helpers import utils
2726

2827
TEST_LAUNCH_ID = 'test_launch_id'
2928

3029

31-
@mock.patch(REPORT_PORTAL_SERVICE)
32-
def test_rp_launch_id(mock_client_init):
30+
@mock.patch(REQUESTS_SERVICE)
31+
def test_rp_launch_id(mock_requests_init):
3332
"""Verify that RP plugin does not start/stop launch if 'rp_launch_id' set.
3433
35-
:param mock_client_init: Pytest fixture
34+
:param mock_requests_init: mocked requests lib
3635
"""
3736
variables = dict()
3837
variables['rp_launch_id'] = TEST_LAUNCH_ID
3938
variables.update(utils.DEFAULT_VARIABLES.items())
40-
result = utils.run_pytest_tests(tests=['examples/test_simple.py'],
41-
variables=variables)
42-
39+
result = utils.run_pytest_tests(tests=['examples/test_simple.py'], variables=variables)
4340
assert int(result) == 0, 'Exit code should be 0 (no errors)'
4441

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()
42+
mock_requests = mock_requests_init.return_value
43+
assert mock_requests.post.call_count == 1
44+
item_start = mock_requests.post.call_args_list[0]
45+
assert item_start[0][0].endswith('/item')
46+
assert item_start[1]['json']['launchUuid'] == TEST_LAUNCH_ID
5947

6048

6149
@mock.patch(REPORT_PORTAL_SERVICE)
@@ -68,8 +56,7 @@ def test_rp_parent_item_id(mock_client_init):
6856
variables = dict()
6957
variables['rp_parent_item_id'] = parent_id
7058
variables.update(utils.DEFAULT_VARIABLES.items())
71-
result = utils.run_pytest_tests(tests=['examples/test_simple.py'],
72-
variables=variables)
59+
result = utils.run_pytest_tests(tests=['examples/test_simple.py'], variables=variables)
7360

7461
assert int(result) == 0, 'Exit code should be 0 (no errors)'
7562

@@ -87,34 +74,25 @@ def test_rp_parent_item_id(mock_client_init):
8774
assert_expectations()
8875

8976

90-
@mock.patch(REPORT_PORTAL_SERVICE)
91-
def test_rp_parent_item_id_and_rp_launch_id(mock_client_init):
77+
@mock.patch(REQUESTS_SERVICE)
78+
def test_rp_parent_item_id_and_rp_launch_id(mock_requests_init):
9279
"""Verify RP handles both conf props 'rp_parent_item_id' & 'rp_launch_id'.
9380
94-
:param mock_client_init: Pytest fixture
81+
:param mock_requests_init: mocked requests lib
9582
"""
9683
parent_id = "parent_id"
9784
variables = dict()
9885
variables['rp_parent_item_id'] = parent_id
99-
variables['rp_launch_id'] = "test_launch_id"
86+
variables['rp_launch_id'] = TEST_LAUNCH_ID
10087
variables.update(utils.DEFAULT_VARIABLES.items())
101-
result = utils.run_pytest_tests(tests=['examples/test_simple.py'],
102-
variables=variables)
103-
88+
result = utils.run_pytest_tests(tests=['examples/test_simple.py'], variables=variables)
10489
assert int(result) == 0, 'Exit code should be 0 (no errors)'
10590

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
114-
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()
91+
mock_requests = mock_requests_init.return_value
92+
assert mock_requests.post.call_count == 1
93+
item_start = mock_requests.post.call_args_list[0]
94+
assert item_start[0][0].endswith(f'/item/{parent_id}')
95+
assert item_start[1]['json']['launchUuid'] == TEST_LAUNCH_ID
11896

11997

12098
@mock.patch(REPORT_PORTAL_SERVICE)

tests/unit/test_plugin.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
"""This module includes unit tests for the plugin."""
1515

16-
from _pytest.config.argparsing import Parser
17-
import pytest
18-
from delayed_assert import expect, assert_expectations
19-
from requests.exceptions import RequestException
2016
# noinspection PyUnresolvedReferences
2117
from unittest import mock
2218

19+
import pytest
20+
from _pytest.config.argparsing import Parser
21+
from delayed_assert import expect, assert_expectations
2322
from reportportal_client.errors import ResponseError
23+
from requests.exceptions import RequestException
2424

2525
from pytest_reportportal.config import AgentConfig
2626
from pytest_reportportal.plugin import (
@@ -258,10 +258,8 @@ def test_pytest_sessionstart(mocked_session):
258258
:param mocked_session: pytest fixture
259259
"""
260260
mocked_session.config.pluginmanager.hasplugin.return_value = True
261-
mocked_session.config._reporter_config = mock.Mock(
262-
spec=AgentConfig(mocked_session.config))
261+
mocked_session.config._reporter_config = mock.Mock(spec=AgentConfig(mocked_session.config))
263262
mocked_session.config._reporter_config.rp_launch_attributes = []
264-
mocked_session.config._reporter_config.rp_launch_id = None
265263
mocked_session.config.py_test_service = mock.Mock()
266264
pytest_sessionstart(mocked_session)
267265
expect(lambda: mocked_session.config.py_test_service.init_service.called)
@@ -298,22 +296,20 @@ def test_pytest_sessionstart_launch_wait_fail(mocked_log, mocked_session):
298296
)
299297

300298

301-
@mock.patch('pytest_reportportal.plugin.is_control', mock.Mock())
302299
@mock.patch('pytest_reportportal.plugin.wait_launch', mock.Mock())
303-
def test_pytest_sessionstart_with_launch_id(mocked_session):
304-
"""Test session configuration if RP launch ID is set via command-line.
300+
def test_pytest_sessionstart_xdist(mocked_session):
301+
"""Test session configuration if it's worker xdist node.
305302
306303
:param mocked_session: pytest fixture
307304
"""
308305
mocked_session.config.pluginmanager.hasplugin.return_value = True
309-
mocked_session.config._reporter_config = mock.Mock(
310-
spec=AgentConfig(mocked_session.config))
306+
mocked_session.config._reporter_config = mock.Mock(spec=AgentConfig(mocked_session.config))
311307
mocked_session.config._reporter_config.rp_launch_attributes = []
312308
mocked_session.config._reporter_config.rp_launch_id = 1
309+
mocked_session.config.workerinput = 1
313310
mocked_session.config.py_test_service = mock.Mock()
314311
pytest_sessionstart(mocked_session)
315-
expect(lambda: mocked_session.config.py_test_service.start_launch.
316-
assert_not_called())
312+
expect(lambda: mocked_session.config.py_test_service.start_launch.assert_not_called())
317313
assert_expectations()
318314

319315

0 commit comments

Comments
 (0)