Skip to content

Commit

Permalink
Merge pull request #219 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth committed Sep 25, 2023
2 parents e566fa4 + f06adf0 commit 34c7000
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 80 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[flake8]
exclude = .git,venv,env
max-line-length = 119
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog

## [Unreleased]
### Changed
- Unified ReportPortal product naming, by @HardNorth
- `RPClient` internal item stack implementation changed to `LifoQueue` to maintain concurrency better, by @HardNorth
### Removed
- Unused `delayed_assert` dependency, by @HardNorth

## [5.4.0]
### Added
- `launch_uuid_print` and `print_output` arguments in `RPClient` class constructor, by @HardNorth
### Removed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ from reportportal_client.helpers import timestamp

endpoint = "http://docker.local:8080"
project = "default"
# You can get UUID from user profile page in the Report Portal.
# You can get UUID from user profile page in the ReportPortal.
api_key = "1adf271d-505f-44a8-ad71-0afbdf8c83bd"
launch_name = "Test launch"
launch_doc = "Testing logging with attachment."
Expand Down
10 changes: 5 additions & 5 deletions reportportal_client/_local/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Report Portal client context storing and retrieving module."""
"""ReportPortal client context storing and retrieving module."""

# Copyright (c) 2022 EPAM Systems
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,17 +19,17 @@


def current():
"""Return current Report Portal client."""
"""Return current ReportPortal client."""
if hasattr(__INSTANCES, 'current'):
return __INSTANCES.current


def set_current(client):
"""Save Report Portal client as current.
"""Save ReportPortal client as current.
The method is not intended to use used by users. Report Portal client calls
The method is not intended to use used by users. ReportPortal client calls
it itself when new client is created.
:param client: Report Portal client
:param client: ReportPortal client
"""
__INSTANCES.current = client
44 changes: 30 additions & 14 deletions reportportal_client/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This module contains Report Portal Client class."""
"""This module contains ReportPortal Client class."""

# Copyright (c) 2023 EPAM Systems
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,6 +17,7 @@
import sys
import warnings
from os import getenv
from queue import LifoQueue
from typing import Union, Tuple, List, Dict, Any, Optional, TextIO

import requests
Expand All @@ -41,11 +42,18 @@
logger.addHandler(logging.NullHandler())


class _LifoQueue(LifoQueue):
def last(self):
with self.mutex:
if self._qsize():
return self.queue[-1]


class RPClient:
"""Report portal client.
"""ReportPortal client.
The class is supposed to use by Report Portal agents: both custom and
official to make calls to Report Portal. It handles HTTP request and
The class is supposed to use by ReportPortal agents: both custom and
official to make calls to RReportPortal. It handles HTTP request and
response bodies generation and serialization, connection retries and log
batching.
NOTICE: the class is not thread-safe, use new class instance for every new
Expand Down Expand Up @@ -74,7 +82,7 @@ class RPClient:
launch_uuid_print: Optional[bool] = ...
print_output: Optional[TextIO] = ...
_skip_analytics: str = ...
_item_stack: List[str] = ...
_item_stack: _LifoQueue = ...

def __init__(
self,
Expand All @@ -96,7 +104,7 @@ def __init__(
) -> None:
"""Initialize required attributes.
:param endpoint: Endpoint of the report portal service
:param endpoint: Endpoint of the ReportPortal service
:param project: Project name to report to
:param api_key: Authorization API key
:param log_batch_size: Option to set the maximum number of
Expand Down Expand Up @@ -133,7 +141,7 @@ def __init__(
self.max_pool_size = max_pool_size
self.http_timeout = http_timeout
self.step_reporter = StepReporter(self)
self._item_stack = []
self._item_stack = _LifoQueue()
self.mode = mode
self._skip_analytics = getenv('AGENT_NO_ANALYTICS')
self.launch_uuid_print = launch_uuid_print
Expand Down Expand Up @@ -262,7 +270,7 @@ def finish_test_item(self,
verify_ssl=self.verify_ssl).make()
if not response:
return
self._item_stack.pop() if len(self._item_stack) > 0 else None
self._remove_current_item()
logger.debug('finish_test_item - ID: %s', item_id)
logger.debug('response message: %s', response.message)
return response.message
Expand Down Expand Up @@ -343,7 +351,7 @@ def get_project_settings(self) -> Optional[Dict]:

def log(self, time: str, message: str, level: Optional[Union[int, str]] = None,
attachment: Optional[Dict] = None, item_id: Optional[str] = None) -> None:
"""Send log message to the Report Portal.
"""Send log message to the ReportPortal.
:param time: Time in UTC
:param message: Log message text
Expand Down Expand Up @@ -422,7 +430,7 @@ def start_launch(self,
self._log_manager.launch_id = self.launch_id = response.id
logger.debug('start_launch - ID: %s', self.launch_id)
if self.launch_uuid_print and self.print_output:
print(f'Report Portal Launch UUID: {self.launch_id}', file=self.print_output)
print(f'ReportPortal Launch UUID: {self.launch_id}', file=self.print_output)
return self.launch_id

def start_test_item(self,
Expand Down Expand Up @@ -488,7 +496,7 @@ def start_test_item(self,
item_id = response.id
if item_id is not NOT_FOUND:
logger.debug('start_test_item - ID: %s', item_id)
self._item_stack.append(item_id)
self._add_current_item(item_id)
else:
logger.warning('start_test_item - invalid response: %s',
str(response.json))
Expand All @@ -500,7 +508,7 @@ def terminate(self, *_: Any, **__: Any) -> None:

def update_test_item(self, item_uuid: str, attributes: Optional[Union[List, Dict]] = None,
description: Optional[str] = None) -> Optional[str]:
"""Update existing test item at the Report Portal.
"""Update existing test item at the ReportPortal.
:param str item_uuid: Test item UUID returned on the item start
:param str description: Test item description
Expand All @@ -520,9 +528,17 @@ def update_test_item(self, item_uuid: str, attributes: Optional[Union[List, Dict
logger.debug('update_test_item - Item: %s', item_id)
return response.message

def _add_current_item(self, item: str) -> None:
"""Add the last item from the self._items queue."""
self._item_stack.put(item)

def _remove_current_item(self) -> str:
"""Remove the last item from the self._items queue."""
return self._item_stack.get()

def current_item(self) -> Optional[str]:
"""Retrieve the last item reported by the client."""
return self._item_stack[-1] if len(self._item_stack) > 0 else None
return self._item_stack.last()

def clone(self) -> 'RPClient':
"""Clone the client object, set current Item ID as cloned item ID.
Expand All @@ -546,7 +562,7 @@ def clone(self) -> 'RPClient':
)
current_item = self.current_item()
if current_item:
cloned._item_stack.append(current_item)
cloned._add_current_item(current_item)
return cloned

def __getstate__(self) -> Dict[str, Any]:
Expand Down
4 changes: 2 additions & 2 deletions reportportal_client/core/rp_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, session_method, url, data=None, json=None,
self.name = name

def make(self):
"""Make HTTP request to the Report Portal API."""
"""Make HTTP request to the ReportPortal API."""
try:
return RPResponse(self.session_method(
self.url, data=self.data, json=self.json,
Expand All @@ -78,7 +78,7 @@ def make(self):
# https://github.com/reportportal/client-Python/issues/39
except (KeyError, IOError, ValueError, TypeError) as exc:
logger.warning(
"Report Portal %s request failed",
"ReportPortal %s request failed",
self.name,
exc_info=exc
)
Expand Down
6 changes: 3 additions & 3 deletions reportportal_client/core/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self,
:param session: Session object
:param endpoint: Endpoint url
:param launch_id: Report portal launch UUID
:param launch_id: ReportPortal launch UUID
:param project_name: RP project name
"""
self.session = session
Expand Down Expand Up @@ -124,7 +124,7 @@ def start_test_item(self,

def update_test_item(self, api_version, item_uuid, attributes=None,
description=None, **kwargs):
"""Update existing test item at the Report Portal.
"""Update existing test item at the ReportPortal.
:param api_version: RP API version
:param str item_uuid: test item UUID returned on the item start
Expand Down Expand Up @@ -201,7 +201,7 @@ def get_test_item(self, item_uuid):
:param item_uuid: test item uuid
:return: test item object if found else None
"""
# Todo: add 'force' parameter to get item from report portal server
# Todo: add 'force' parameter to get item from ReportPortal server
# instead of cache and update cache data according to this request
return self._find_item(item_uuid, self.__storage)

Expand Down
2 changes: 1 addition & 1 deletion reportportal_client/core/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __lt__(self, other):


class APIWorker(object):
"""Worker that makes HTTP requests to the Report Portal."""
"""Worker that makes HTTP requests to the ReportPortal."""

def __init__(self, task_queue):
"""Initialize instance attributes."""
Expand Down
2 changes: 1 addition & 1 deletion reportportal_client/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def dict_to_payload(dictionary):
"""Convert incoming dictionary to the list of dictionaries.
This function transforms the given dictionary of tags/attributes into
the format required by the Report Portal API. Also, we add the system
the format required by the ReportPortal API. Also, we add the system
key to every tag/attribute that indicates that the key should be hidden
from the user in UI.
:param dictionary: Dictionary containing tags/attributes
Expand Down
2 changes: 1 addition & 1 deletion reportportal_client/items/rp_base_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, rp_url, session, project_name,
launch_uuid, generated_id):
"""Initialize instance attributes.
:param rp_url: report portal url
:param rp_url: ReportPortal url
:param session: Session object
:param project_name: RP project name
:param launch_uuid: Parent launch UUID
Expand Down
2 changes: 1 addition & 1 deletion reportportal_client/items/rp_log_items/rp_log_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, rp_url, session, project_name,
launch_uuid, generated_id):
"""Initialize instance attributes.
:param rp_url: report portal URL
:param rp_url: ReportPortal URL
:param session: Session object
:param project_name: RP project name
:param launch_uuid: Parent launch UUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, rp_url, session, project_name, item_name,
item_type, launch_uuid, generated_id, **kwargs):
"""Initialize instance attributes.
:param rp_url: report portal url
:param rp_url: ReportPortal url
:param session: Session object
:param project_name: RP project name
:param item_name: RP item name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, rp_url, session, project_name, parent_item,
**kwargs):
"""Initialize instance attributes.
:param rp_url: report portal url
:param rp_url: ReportPortal url
:param session: Session object
:param project_name: RP project name
:param item_name: RP item name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, rp_url, session, project_name, item_name,
item_type, launch_uuid, generated_id, **kwargs):
"""Initialize instance attributes.
:param rp_url: report portal url
:param rp_url: ReportPortal url
:param session: Session object
:param project_name: RP project name
:param item_name: RP item name
Expand Down
13 changes: 6 additions & 7 deletions reportportal_client/logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License
"""Report portal logging handling module."""
"""ReportPortal logging handling module."""

import logging
import sys
Expand Down Expand Up @@ -111,12 +111,11 @@ def __init__(self, level=logging.NOTSET, filter_client_logs=False,
:param level: level of logging
:param filter_client_logs: if True throw away logs emitted by a
ReportPortal client
:param endpoint: Report Portal endpoint URL, used to filter
out urllib3 logs, mutes Report Portal HTTP logs if set, optional
parameter
:param ignored_record_names: a tuple of record names which will be
filtered out by the handler (with startswith method)
ReportPortal client
:param endpoint: ReportPortal endpoint URL, used to filter out urllib3 logs, mutes
ReportPortal HTTP logs if set, optional parameter
:param ignored_record_names: a tuple of record names which will be filtered out by the handler
(with startswith method)
"""
super(RPLogHandler, self).__init__(level)
self.filter_client_logs = filter_client_logs
Expand Down
2 changes: 1 addition & 1 deletion reportportal_client/logs/log_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, rp_url, session, api_version, launch_id, project_name,
max_payload_size=MAX_LOG_BATCH_PAYLOAD_SIZE):
"""Initialize instance attributes.
:param rp_url: Report portal URL
:param rp_url: ReportPortal URL
:param session: HTTP Session object
:param api_version: RP API version
:param launch_id: Parent launch UUID
Expand Down
Loading

0 comments on commit 34c7000

Please sign in to comment.