Skip to content

Commit 95ffb2c

Browse files
committed
RP_CONNECT_TIMEOUT and RP_READ_TIMEOUT configuration variables
1 parent 1500138 commit 95ffb2c

File tree

7 files changed

+58
-5
lines changed

7 files changed

+58
-5
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
### Added
55
- `RP_CLIENT_TYPE` configuration variable, by @HardNorth
6+
- `RP_CONNECT_TIMEOUT` and `RP_READ_TIMEOUT` configuration variables, by @HardNorth
67
### Changed
78
- Client version updated on [5.5.1](https://github.com/reportportal/client-Python/releases/tag/5.5.1), by @HardNorth
89

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Example of :code:`pytest.ini`:
8181

8282
The following parameters are optional:
8383

84+
- :code:`rp_client_type = SYNC` - Type of the under-the-hood ReportPortal client implementation. Possible values: [SYNC, ASYNC_THREAD, ASYNC_BATCHED].
8485
- :code:`rp_launch = AnyLaunchName` - launch name (could be overridden by pytest --rp-launch option, default value is 'Pytest Launch').
8586
- :code:`rp_launch_id = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` - id of the existing launch (the session will not handle the lifecycle of the given launch).
8687
- :code:`rp_launch_attributes = 'PyTest' 'Smoke' 'Env:Python3'` - list of attributes for launch.
@@ -90,6 +91,8 @@ The following parameters are optional:
9091
- :code:`rp_launch_uuid_print_output = stderr` - Launch UUID print output. Default `stdout`. Possible values: [stderr, stdout].
9192
- :code:`rp_parent_item_id = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` - id of the existing test item for session to use as parent item for the tests (the session will not handle the lifecycle of the given test item).
9293
- :code:`rp_tests_attributes = 'PyTest' 'Smoke'` - list of attributes that will be added for each item in the launch.
94+
- :code:`rp_connect_timeout = 15` - Connection timeout to ReportPortal server. Default value is "10.0".
95+
- :code:`rp_read_timeout = 15` - Response read timeout for ReportPortal connection. Default value is "10.0".
9396
- :code:`rp_log_batch_size = 20` - size of batch log request.
9497
- :code:`rp_log_batch_payload_size = 65000000` - maximum payload size in bytes of async batch log requests.
9598
- :code:`rp_log_level = INFO` - The log level that will be reported.

pytest_reportportal/config.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import warnings
1717
from distutils.util import strtobool
1818
from os import getenv
19-
from typing import Optional, Union, Any
19+
from typing import Optional, Union, Any, Tuple
2020

2121
from _pytest.config import Config
2222
from reportportal_client import OutputType, ClientType
@@ -66,6 +66,7 @@ class AgentConfig(object):
6666
rp_launch_timeout: int
6767
rp_launch_uuid_print: bool
6868
rp_launch_uuid_print_output: Optional[OutputType]
69+
rp_http_timeout: Optional[Union[Tuple[float, float], float]]
6970

7071
def __init__(self, pytest_config: Config) -> None:
7172
"""Initialize required attributes."""
@@ -182,6 +183,17 @@ def __init__(self, pytest_config: Config) -> None:
182183
client_type = self.find_option(pytest_config, 'rp_client_type')
183184
self.rp_client_type = ClientType[client_type.upper()] if client_type else ClientType.SYNC
184185

186+
connect_timeout = self.find_option(pytest_config, 'rp_connect_timeout')
187+
connect_timeout = float(connect_timeout) if connect_timeout else None
188+
read_timeout = self.find_option(pytest_config, 'rp_read_timeout')
189+
read_timeout = float(read_timeout) if read_timeout else None
190+
if connect_timeout is None and read_timeout is None:
191+
self.rp_http_timeout = None
192+
elif connect_timeout is not None and read_timeout is not None:
193+
self.rp_http_timeout = (connect_timeout, read_timeout)
194+
else:
195+
self.rp_http_timeout = connect_timeout or read_timeout
196+
185197
# noinspection PyMethodMayBeStatic
186198
def find_option(self, pytest_config: Config, option_name: str, default: Any = None) -> Any:
187199
"""

pytest_reportportal/plugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,11 @@ def add_shared_option(name, help_str, default=None, action='store'):
503503
help='Type of the under-the-hood ReportPortal client implementation. Possible values: [SYNC, ASYNC_THREAD, '
504504
'ASYNC_BATCHED]'
505505
)
506+
parser.addini(
507+
'rp_connect_timeout',
508+
help='Connection timeout to ReportPortal server'
509+
)
510+
parser.addini(
511+
'rp_read_timeout',
512+
help='Response read timeout for ReportPortal connection'
513+
)

pytest_reportportal/service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,8 @@ def start(self) -> None:
912912
launch_id=launch_id,
913913
log_batch_payload_size=self._config.rp_log_batch_payload_size,
914914
launch_uuid_print=self._config.rp_launch_uuid_print,
915-
print_output=self._config.rp_launch_uuid_print_output
915+
print_output=self._config.rp_launch_uuid_print_output,
916+
http_timeout=self._config.rp_http_timeout
916917
)
917918
if hasattr(self.rp, "get_project_settings"):
918919
self.project_settings = self.rp.get_project_settings()

tests/integration/test_config_handling.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import warnings
1717
from unittest import mock
1818

19+
import pytest
20+
1921
from delayed_assert import expect, assert_expectations
2022
from reportportal_client import OutputType
2123

@@ -248,8 +250,7 @@ def test_rp_api_retries(mock_client_init):
248250
variables.update({'rp_api_retries': str(retries)}.items())
249251

250252
with warnings.catch_warnings(record=True) as w:
251-
result = utils.run_pytest_tests(['examples/test_rp_logging.py'],
252-
variables=variables)
253+
result = utils.run_pytest_tests(['examples/test_rp_logging.py'], variables=variables)
253254
assert int(result) == 0, 'Exit code should be 0 (no errors)'
254255

255256
expect(mock_client_init.call_count == 1)
@@ -324,3 +325,28 @@ def test_no_launch_uuid_print(mock_client_init):
324325
expect(mock_client_init.call_args_list[0][1]['launch_uuid_print'] is False)
325326
expect(mock_client_init.call_args_list[0][1]['print_output'] is None)
326327
assert_expectations()
328+
329+
330+
@pytest.mark.parametrize(
331+
'connect_value, read_value, expected_result',
332+
[
333+
('5', '15', (5.0, 15.0)),
334+
('5.5', '15.5', (5.5, 15.5)),
335+
(None, None, None),
336+
(None, '5', 5),
337+
('5', None, 5)
338+
]
339+
)
340+
@mock.patch(REPORT_PORTAL_SERVICE)
341+
def test_client_timeouts(mock_client_init, connect_value, read_value, expected_result):
342+
variables = utils.DEFAULT_VARIABLES.copy()
343+
if connect_value:
344+
variables['rp_connect_timeout'] = connect_value
345+
if read_value:
346+
variables['rp_read_timeout'] = read_value
347+
348+
result = utils.run_pytest_tests(['examples/test_rp_logging.py'], variables=variables)
349+
350+
assert int(result) == 0, 'Exit code should be 0 (no errors)'
351+
assert mock_client_init.call_count == 1
352+
assert mock_client_init.call_args_list[0][1]['http_timeout'] == expected_result

tests/unit/test_plugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ def test_pytest_addoption_adds_correct_ini_file_arguments():
367367
'rp_api_retries',
368368
'rp_skip_connection_test',
369369
'rp_launch_timeout',
370-
'rp_client_type'
370+
'rp_client_type',
371+
'rp_connect_timeout',
372+
'rp_read_timeout'
371373
)
372374
mock_parser = mock.MagicMock(spec=Parser)
373375

0 commit comments

Comments
 (0)