Skip to content

Commit 50676ac

Browse files
authored
Merge pull request #351 from reportportal/develop
Release
2 parents 2b97419 + 7e52e79 commit 50676ac

34 files changed

+359
-229
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
run: tox
4040

4141
- name: Upload coverage to Codecov
42-
if: matrix.python-version == 3.7 && success()
42+
if: matrix.python-version == 3.8 && success()
4343
uses: codecov/codecov-action@v3
4444
with:
4545
files: coverage.xml

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Added
5+
- `RP_CLIENT_TYPE` configuration variable, by @HardNorth
6+
- `RP_CONNECT_TIMEOUT` and `RP_READ_TIMEOUT` configuration variables, by @HardNorth
7+
### Changed
8+
- Client version updated on [5.5.2](https://github.com/reportportal/client-Python/releases/tag/5.5.2), by @HardNorth
9+
10+
## [5.2.2]
411
### Changed
512
- Client version updated on [5.4.1](https://github.com/reportportal/client-Python/releases/tag/5.4.1), by @HardNorth
613

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/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
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+
114
"""This package contains Pytest agent's code for the Report Portal."""
215

316
__all__ = ['LAUNCH_WAIT_TIMEOUT']

pytest_reportportal/config.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
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+
114
"""This module contains class that stores RP agent configuration data."""
2-
import sys
3-
import warnings
415

16+
import warnings
517
from distutils.util import strtobool
618
from os import getenv
7-
from typing import Optional, Union, Any, TextIO, Dict
19+
from typing import Optional, Union, Any, Tuple
820

921
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
1124

1225
try:
1326
# This try/except can go away once we support pytest >= 5.4.0
@@ -17,15 +30,10 @@
1730
get_actual_log_level
1831

1932

20-
OUTPUT_TYPES: Dict[str, TextIO] = {
21-
'stdout': sys.stdout,
22-
'stderr': sys.stderr
23-
}
24-
25-
2633
class AgentConfig(object):
2734
"""Storage for the RP agent initialization attributes."""
2835

36+
rp_client_type: Optional[ClientType]
2937
rp_rerun: Optional[bool]
3038
pconfig: Config
3139
rp_endpoint: str
@@ -57,7 +65,8 @@ class AgentConfig(object):
5765
rp_verify_ssl: Union[bool, str]
5866
rp_launch_timeout: int
5967
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]]
6170

6271
def __init__(self, pytest_config: Config) -> None:
6372
"""Initialize required attributes."""
@@ -169,12 +178,24 @@ def __init__(self, pytest_config: Config) -> None:
169178
self.rp_launch_uuid_print = bool(strtobool(self.find_option(
170179
pytest_config, 'rp_launch_uuid_print'
171180
) 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
175196

176197
# 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:
178199
"""
179200
Find a single configuration setting from multiple places.
180201

pytest_reportportal/errors.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
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+
114
"""This module includes exceptions used in the package."""
215

316

pytest_reportportal/plugin.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""This module contains changed pytest for report-portal."""
2-
31
# Copyright (c) 2023 https://reportportal.io .
42
# Licensed under the Apache License, Version 2.0 (the "License");
53
# you may not use this file except in compliance with the License.
@@ -13,6 +11,8 @@
1311
# See the License for the specific language governing permissions and
1412
# limitations under the License
1513

14+
"""This module contains changed pytest for ReportPortal."""
15+
1616
import logging
1717
import os.path
1818
import time
@@ -23,7 +23,7 @@
2323
import requests
2424
from reportportal_client import RPLogHandler
2525
from reportportal_client.errors import ResponseError
26-
from reportportal_client.logs.log_manager import MAX_LOG_BATCH_PAYLOAD_SIZE
26+
from reportportal_client.logs import MAX_LOG_BATCH_PAYLOAD_SIZE
2727

2828
from pytest_reportportal import LAUNCH_WAIT_TIMEOUT
2929
from .config import AgentConfig
@@ -402,13 +402,11 @@ def add_shared_option(name, help_str, default=None, action='store'):
402402
)
403403
add_shared_option(
404404
name='rp_launch_uuid_print',
405-
help_str='Enables printing Launch UUID on test run start. Possible values: [True, False]',
406-
default='False'
405+
help_str='Enables printing Launch UUID on test run start. Possible values: [True, False]'
407406
)
408407
add_shared_option(
409408
name='rp_launch_uuid_print_output',
410-
help_str='Launch UUID print output. Default `stdout`. Possible values: [stderr, stdout]',
411-
default='stdout'
409+
help_str='Launch UUID print output. Default `stdout`. Possible values: [stderr, stdout]'
412410
)
413411

414412
parser.addini(
@@ -500,3 +498,16 @@ def add_shared_option(name, help_str, default=None, action='store'):
500498
help='Maximum time to wait for child processes finish, default value: '
501499
'86400 seconds (1 day)'
502500
)
501+
parser.addini(
502+
'rp_client_type',
503+
help='Type of the under-the-hood ReportPortal client implementation. Possible values: [SYNC, ASYNC_THREAD, '
504+
'ASYNC_BATCHED]'
505+
)
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/plugin.pyi

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
# Copyright (c) 2023 https://reportportal.io .
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+
114
from logging import Logger
2-
from typing import Text
15+
from typing import Text, Any
316

417
import pytest
518

@@ -8,7 +21,6 @@ from _pytest.config import Config
821
from _pytest.config.argparsing import Parser
922
from _pytest.main import Session
1023
from reportportal_client import RPClient
11-
from xdist.workermanage import WorkerController
1224

1325
log: Logger
1426
MANDATORY_PARAMETER_MISSED_PATTERN: Text
@@ -17,7 +29,7 @@ FAILED_LAUNCH_WAIT: Text
1729
def check_connection(agent_config: AgentConfig) -> bool: ...
1830
def is_control(config: Config) -> bool: ...
1931
def wait_launch(rp_client: RPClient) -> bool: ...
20-
def pytest_configure_node(node: WorkerController) -> None: ...
32+
def pytest_configure_node(node: Any) -> None: ...
2133
def pytest_sessionstart(session: Session) -> None: ...
2234
def pytest_collection_finish(session: Session) -> None: ...
2335
def pytest_sessionfinish(session: Session) -> None: ...

pytest_reportportal/rp_logging.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Copyright (c) 2023 https://reportportal.io .
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+
114
"""RPLogger class for low-level logging in tests."""
215

316
import sys
@@ -6,7 +19,7 @@
619
from contextlib import contextmanager
720
from functools import wraps
821

9-
from reportportal_client._local import current, set_current
22+
from reportportal_client import current, set_current
1023
from reportportal_client import RPLogger
1124
from reportportal_client.core.worker import APIWorker
1225

@@ -62,13 +75,12 @@ def _run(self, *args, **kwargs):
6275
):
6376
parent = self.parent_rp_client
6477
client = parent.clone()
65-
client.start()
6678
try:
6779
return original_func(self, *args, **kwargs)
6880
finally:
6981
if client:
7082
# Stop the client and remove any references
71-
client.terminate()
83+
client.close()
7284
self.parent_rp_client = None
7385
del self.parent_rp_client
7486
set_current(None)

0 commit comments

Comments
 (0)