|
| 1 | +# Copyright (c) 2023 EPAM Systems |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License |
| 13 | + |
1 | 14 | """This module contains class that stores RP agent configuration data.""" |
2 | | -import sys |
3 | | -import warnings |
4 | 15 |
|
| 16 | +import warnings |
5 | 17 | from distutils.util import strtobool |
6 | 18 | from os import getenv |
7 | | -from typing import Optional, Union, Any, TextIO, Dict |
| 19 | +from typing import Optional, Union, Any, Tuple |
8 | 20 |
|
9 | 21 | from _pytest.config import Config |
10 | | -from reportportal_client.logs.log_manager import MAX_LOG_BATCH_PAYLOAD_SIZE |
| 22 | +from reportportal_client import OutputType, ClientType |
| 23 | +from reportportal_client.logs import MAX_LOG_BATCH_PAYLOAD_SIZE |
11 | 24 |
|
12 | 25 | try: |
13 | 26 | # This try/except can go away once we support pytest >= 5.4.0 |
|
17 | 30 | get_actual_log_level |
18 | 31 |
|
19 | 32 |
|
20 | | -OUTPUT_TYPES: Dict[str, TextIO] = { |
21 | | - 'stdout': sys.stdout, |
22 | | - 'stderr': sys.stderr |
23 | | -} |
24 | | - |
25 | | - |
26 | 33 | class AgentConfig(object): |
27 | 34 | """Storage for the RP agent initialization attributes.""" |
28 | 35 |
|
| 36 | + rp_client_type: Optional[ClientType] |
29 | 37 | rp_rerun: Optional[bool] |
30 | 38 | pconfig: Config |
31 | 39 | rp_endpoint: str |
@@ -57,7 +65,8 @@ class AgentConfig(object): |
57 | 65 | rp_verify_ssl: Union[bool, str] |
58 | 66 | rp_launch_timeout: int |
59 | 67 | rp_launch_uuid_print: bool |
60 | | - rp_launch_uuid_print_output: TextIO |
| 68 | + rp_launch_uuid_print_output: Optional[OutputType] |
| 69 | + rp_http_timeout: Optional[Union[Tuple[float, float], float]] |
61 | 70 |
|
62 | 71 | def __init__(self, pytest_config: Config) -> None: |
63 | 72 | """Initialize required attributes.""" |
@@ -169,12 +178,24 @@ def __init__(self, pytest_config: Config) -> None: |
169 | 178 | self.rp_launch_uuid_print = bool(strtobool(self.find_option( |
170 | 179 | pytest_config, 'rp_launch_uuid_print' |
171 | 180 | ) or 'False')) |
172 | | - self.rp_launch_uuid_print_output = OUTPUT_TYPES.get((self.find_option( |
173 | | - pytest_config, 'rp_launch_uuid_print_output' |
174 | | - ) or 'stdout').lower(), OUTPUT_TYPES['stdout']) |
| 181 | + print_output = self.find_option(pytest_config, 'rp_launch_uuid_print_output') |
| 182 | + self.rp_launch_uuid_print_output = OutputType[print_output.upper()] if print_output else None |
| 183 | + client_type = self.find_option(pytest_config, 'rp_client_type') |
| 184 | + self.rp_client_type = ClientType[client_type.upper()] if client_type else ClientType.SYNC |
| 185 | + |
| 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 |
175 | 196 |
|
176 | 197 | # noinspection PyMethodMayBeStatic |
177 | | - def find_option(self, pytest_config: Config, option_name: str, default: Any = None): |
| 198 | + def find_option(self, pytest_config: Config, option_name: str, default: Any = None) -> Any: |
178 | 199 | """ |
179 | 200 | Find a single configuration setting from multiple places. |
180 | 201 |
|
|
0 commit comments