Skip to content

Commit

Permalink
Client version update
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Oct 17, 2023
1 parent 374cd41 commit 15c25f6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
### Added
- `RP_CLIENT_TYPE` configuration variable, by @HardNorth
### Changed
- Client version updated on [5.5.1](https://github.com/reportportal/client-Python/releases/tag/5.5.1), by @HardNorth

## [5.2.2]
### Changed
Expand Down
25 changes: 10 additions & 15 deletions pytest_reportportal/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""This module contains class that stores RP agent configuration data."""
import sys
import warnings

from distutils.util import strtobool
from os import getenv
from typing import Optional, Union, Any, TextIO, Dict
from typing import Optional, Union, Any

from _pytest.config import Config
from reportportal_client.logs.log_manager import MAX_LOG_BATCH_PAYLOAD_SIZE
from reportportal_client import OutputType, ClientType
from reportportal_client.logs import MAX_LOG_BATCH_PAYLOAD_SIZE

try:
# This try/except can go away once we support pytest >= 5.4.0
Expand All @@ -17,15 +16,10 @@
get_actual_log_level


OUTPUT_TYPES: Dict[str, TextIO] = {
'stdout': sys.stdout,
'stderr': sys.stderr
}


class AgentConfig(object):
"""Storage for the RP agent initialization attributes."""

rp_client_type: Optional[ClientType]
rp_rerun: Optional[bool]
pconfig: Config
rp_endpoint: str
Expand Down Expand Up @@ -57,7 +51,7 @@ class AgentConfig(object):
rp_verify_ssl: Union[bool, str]
rp_launch_timeout: int
rp_launch_uuid_print: bool
rp_launch_uuid_print_output: TextIO
rp_launch_uuid_print_output: Optional[OutputType]

def __init__(self, pytest_config: Config) -> None:
"""Initialize required attributes."""
Expand Down Expand Up @@ -169,12 +163,13 @@ def __init__(self, pytest_config: Config) -> None:
self.rp_launch_uuid_print = bool(strtobool(self.find_option(
pytest_config, 'rp_launch_uuid_print'
) or 'False'))
self.rp_launch_uuid_print_output = OUTPUT_TYPES.get((self.find_option(
pytest_config, 'rp_launch_uuid_print_output'
) or 'stdout').lower(), OUTPUT_TYPES['stdout'])
print_output = self.find_option(pytest_config, 'rp_launch_uuid_print_output')
self.rp_launch_uuid_print_output = OutputType[print_output] if print_output else None
client_type = self.find_option(pytest_config, 'rp_client_type')
self.rp_client_type = ClientType[client_type.upper()] if client_type else ClientType.SYNC

# noinspection PyMethodMayBeStatic
def find_option(self, pytest_config: Config, option_name: str, default: Any = None):
def find_option(self, pytest_config: Config, option_name: str, default: Any = None) -> Any:
"""
Find a single configuration setting from multiple places.
Expand Down
31 changes: 18 additions & 13 deletions pytest_reportportal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
from functools import wraps
from os import curdir
from time import time, sleep
from typing import List, Any, Optional, Set, Dict, Tuple
from typing import List, Any, Optional, Set, Dict, Tuple, Union

from _pytest.doctest import DoctestItem
from aenum import auto, Enum, unique
from pytest import Class, Function, Module, Package, Item, Session, \
PytestWarning
from reportportal_client.core.rp_issues import Issue, ExternalIssue
from reportportal_client.aio import Task

from .config import AgentConfig

Expand All @@ -21,7 +22,7 @@
except ImportError:
# in pytest >= 7.0 this type was removed
Instance = type('dummy', (), {})
from reportportal_client.client import RPClient
from reportportal_client import RP, create_client
from reportportal_client.helpers import (
dict_to_payload,
gen_attributes,
Expand Down Expand Up @@ -123,8 +124,8 @@ class PyTestServiceClass:
agent_version: str
ignored_attributes: List[str]
parent_item_id: Optional[str]
rp: Optional[RPClient]
project_settings: Dict[str, Any]
rp: Optional[RP]
project_settings: Union[Dict[str, Any], Task]

def __init__(self, agent_config: AgentConfig) -> None:
"""Initialize instance attributes."""
Expand All @@ -144,12 +145,16 @@ def __init__(self, agent_config: AgentConfig) -> None:
@property
def issue_types(self) -> Dict[str, str]:
"""Issue types for the Report Portal project."""
if not self._issue_types:
if not self.project_settings:
return self._issue_types
for values in self.project_settings["subTypes"].values():
for item in values:
self._issue_types[item["shortName"]] = item["locator"]
if self._issue_types:
return self._issue_types
if not self.project_settings:
return self._issue_types
project_settings = self.project_settings
if not isinstance(self.project_settings, dict):
project_settings = project_settings.blocking_result()
for values in project_settings["subTypes"].values():
for item in values:
self._issue_types[item["shortName"]] = item["locator"]
return self._issue_types

def _get_launch_attributes(self, ini_attrs):
Expand Down Expand Up @@ -881,7 +886,8 @@ def start(self) -> None:
launch_id = self._launch_id
if self._config.rp_launch_id:
launch_id = self._config.rp_launch_id
self.rp = RPClient(
self.rp = create_client(
client_type=self._config.rp_client_type,
endpoint=self._config.rp_endpoint,
project=self._config.rp_project,
api_key=self._config.rp_api_key,
Expand All @@ -896,12 +902,11 @@ def start(self) -> None:
)
if hasattr(self.rp, "get_project_settings"):
self.project_settings = self.rp.get_project_settings()
self.rp.start()
# noinspection PyUnresolvedReferences
self._start_tracker.add(self.__unique_id())

def stop(self):
"""Finish servicing Report Portal requests."""
self.rp.terminate()
self.rp.close()
self.rp = None
self._start_tracker.remove(self.__unique_id())
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dill>=0.3.6
pytest>=3.8.0
reportportal-client==5.4.1
reportportal-client~=5.5.1
aenum>=3.1.0
requests>=2.27.1
requests>=2.28.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools import setup


__version__ = '5.2.3'
__version__ = '5.3.0'


def read_file(fname):
Expand Down

0 comments on commit 15c25f6

Please sign in to comment.