Skip to content

Commit 34c7000

Browse files
authored
Merge pull request #219 from reportportal/develop
Release
2 parents e566fa4 + f06adf0 commit 34c7000

23 files changed

+102
-80
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[flake8]
2+
exclude = .git,venv,env
23
max-line-length = 119

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+
### Changed
5+
- Unified ReportPortal product naming, by @HardNorth
6+
- `RPClient` internal item stack implementation changed to `LifoQueue` to maintain concurrency better, by @HardNorth
7+
### Removed
8+
- Unused `delayed_assert` dependency, by @HardNorth
9+
10+
## [5.4.0]
411
### Added
512
- `launch_uuid_print` and `print_output` arguments in `RPClient` class constructor, by @HardNorth
613
### Removed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ from reportportal_client.helpers import timestamp
3939

4040
endpoint = "http://docker.local:8080"
4141
project = "default"
42-
# You can get UUID from user profile page in the Report Portal.
42+
# You can get UUID from user profile page in the ReportPortal.
4343
api_key = "1adf271d-505f-44a8-ad71-0afbdf8c83bd"
4444
launch_name = "Test launch"
4545
launch_doc = "Testing logging with attachment."

reportportal_client/_local/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Report Portal client context storing and retrieving module."""
1+
"""ReportPortal client context storing and retrieving module."""
22

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

2020

2121
def current():
22-
"""Return current Report Portal client."""
22+
"""Return current ReportPortal client."""
2323
if hasattr(__INSTANCES, 'current'):
2424
return __INSTANCES.current
2525

2626

2727
def set_current(client):
28-
"""Save Report Portal client as current.
28+
"""Save ReportPortal client as current.
2929
30-
The method is not intended to use used by users. Report Portal client calls
30+
The method is not intended to use used by users. ReportPortal client calls
3131
it itself when new client is created.
3232
33-
:param client: Report Portal client
33+
:param client: ReportPortal client
3434
"""
3535
__INSTANCES.current = client

reportportal_client/client.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This module contains Report Portal Client class."""
1+
"""This module contains ReportPortal Client class."""
22

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

2223
import requests
@@ -41,11 +42,18 @@
4142
logger.addHandler(logging.NullHandler())
4243

4344

45+
class _LifoQueue(LifoQueue):
46+
def last(self):
47+
with self.mutex:
48+
if self._qsize():
49+
return self.queue[-1]
50+
51+
4452
class RPClient:
45-
"""Report portal client.
53+
"""ReportPortal client.
4654
47-
The class is supposed to use by Report Portal agents: both custom and
48-
official to make calls to Report Portal. It handles HTTP request and
55+
The class is supposed to use by ReportPortal agents: both custom and
56+
official to make calls to RReportPortal. It handles HTTP request and
4957
response bodies generation and serialization, connection retries and log
5058
batching.
5159
NOTICE: the class is not thread-safe, use new class instance for every new
@@ -74,7 +82,7 @@ class RPClient:
7482
launch_uuid_print: Optional[bool] = ...
7583
print_output: Optional[TextIO] = ...
7684
_skip_analytics: str = ...
77-
_item_stack: List[str] = ...
85+
_item_stack: _LifoQueue = ...
7886

7987
def __init__(
8088
self,
@@ -96,7 +104,7 @@ def __init__(
96104
) -> None:
97105
"""Initialize required attributes.
98106
99-
:param endpoint: Endpoint of the report portal service
107+
:param endpoint: Endpoint of the ReportPortal service
100108
:param project: Project name to report to
101109
:param api_key: Authorization API key
102110
:param log_batch_size: Option to set the maximum number of
@@ -133,7 +141,7 @@ def __init__(
133141
self.max_pool_size = max_pool_size
134142
self.http_timeout = http_timeout
135143
self.step_reporter = StepReporter(self)
136-
self._item_stack = []
144+
self._item_stack = _LifoQueue()
137145
self.mode = mode
138146
self._skip_analytics = getenv('AGENT_NO_ANALYTICS')
139147
self.launch_uuid_print = launch_uuid_print
@@ -262,7 +270,7 @@ def finish_test_item(self,
262270
verify_ssl=self.verify_ssl).make()
263271
if not response:
264272
return
265-
self._item_stack.pop() if len(self._item_stack) > 0 else None
273+
self._remove_current_item()
266274
logger.debug('finish_test_item - ID: %s', item_id)
267275
logger.debug('response message: %s', response.message)
268276
return response.message
@@ -343,7 +351,7 @@ def get_project_settings(self) -> Optional[Dict]:
343351

344352
def log(self, time: str, message: str, level: Optional[Union[int, str]] = None,
345353
attachment: Optional[Dict] = None, item_id: Optional[str] = None) -> None:
346-
"""Send log message to the Report Portal.
354+
"""Send log message to the ReportPortal.
347355
348356
:param time: Time in UTC
349357
:param message: Log message text
@@ -422,7 +430,7 @@ def start_launch(self,
422430
self._log_manager.launch_id = self.launch_id = response.id
423431
logger.debug('start_launch - ID: %s', self.launch_id)
424432
if self.launch_uuid_print and self.print_output:
425-
print(f'Report Portal Launch UUID: {self.launch_id}', file=self.print_output)
433+
print(f'ReportPortal Launch UUID: {self.launch_id}', file=self.print_output)
426434
return self.launch_id
427435

428436
def start_test_item(self,
@@ -488,7 +496,7 @@ def start_test_item(self,
488496
item_id = response.id
489497
if item_id is not NOT_FOUND:
490498
logger.debug('start_test_item - ID: %s', item_id)
491-
self._item_stack.append(item_id)
499+
self._add_current_item(item_id)
492500
else:
493501
logger.warning('start_test_item - invalid response: %s',
494502
str(response.json))
@@ -500,7 +508,7 @@ def terminate(self, *_: Any, **__: Any) -> None:
500508

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

531+
def _add_current_item(self, item: str) -> None:
532+
"""Add the last item from the self._items queue."""
533+
self._item_stack.put(item)
534+
535+
def _remove_current_item(self) -> str:
536+
"""Remove the last item from the self._items queue."""
537+
return self._item_stack.get()
538+
523539
def current_item(self) -> Optional[str]:
524540
"""Retrieve the last item reported by the client."""
525-
return self._item_stack[-1] if len(self._item_stack) > 0 else None
541+
return self._item_stack.last()
526542

527543
def clone(self) -> 'RPClient':
528544
"""Clone the client object, set current Item ID as cloned item ID.
@@ -546,7 +562,7 @@ def clone(self) -> 'RPClient':
546562
)
547563
current_item = self.current_item()
548564
if current_item:
549-
cloned._item_stack.append(current_item)
565+
cloned._add_current_item(current_item)
550566
return cloned
551567

552568
def __getstate__(self) -> Dict[str, Any]:

reportportal_client/core/rp_requests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, session_method, url, data=None, json=None,
6868
self.name = name
6969

7070
def make(self):
71-
"""Make HTTP request to the Report Portal API."""
71+
"""Make HTTP request to the ReportPortal API."""
7272
try:
7373
return RPResponse(self.session_method(
7474
self.url, data=self.data, json=self.json,
@@ -78,7 +78,7 @@ def make(self):
7878
# https://github.com/reportportal/client-Python/issues/39
7979
except (KeyError, IOError, ValueError, TypeError) as exc:
8080
logger.warning(
81-
"Report Portal %s request failed",
81+
"ReportPortal %s request failed",
8282
self.name,
8383
exc_info=exc
8484
)

reportportal_client/core/test_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self,
4848
4949
:param session: Session object
5050
:param endpoint: Endpoint url
51-
:param launch_id: Report portal launch UUID
51+
:param launch_id: ReportPortal launch UUID
5252
:param project_name: RP project name
5353
"""
5454
self.session = session
@@ -124,7 +124,7 @@ def start_test_item(self,
124124

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

reportportal_client/core/worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __lt__(self, other):
5454

5555

5656
class APIWorker(object):
57-
"""Worker that makes HTTP requests to the Report Portal."""
57+
"""Worker that makes HTTP requests to the ReportPortal."""
5858

5959
def __init__(self, task_queue):
6060
"""Initialize instance attributes."""

reportportal_client/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def dict_to_payload(dictionary):
4747
"""Convert incoming dictionary to the list of dictionaries.
4848
4949
This function transforms the given dictionary of tags/attributes into
50-
the format required by the Report Portal API. Also, we add the system
50+
the format required by the ReportPortal API. Also, we add the system
5151
key to every tag/attribute that indicates that the key should be hidden
5252
from the user in UI.
5353
:param dictionary: Dictionary containing tags/attributes

reportportal_client/items/rp_base_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, rp_url, session, project_name,
2323
launch_uuid, generated_id):
2424
"""Initialize instance attributes.
2525
26-
:param rp_url: report portal url
26+
:param rp_url: ReportPortal url
2727
:param session: Session object
2828
:param project_name: RP project name
2929
:param launch_uuid: Parent launch UUID

0 commit comments

Comments
 (0)