Skip to content

Commit be275f3

Browse files
authored
Merge pull request #211 from reportportal/develop
Release
2 parents b0f5a4f + 1a6123e commit be275f3

File tree

8 files changed

+87
-19
lines changed

8 files changed

+87
-19
lines changed

CHANGELOG.md

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

33
## [Unreleased]
4+
### Added
5+
- `RPClient.clone()` method, by @HardNorth
6+
### Fixed
7+
- Client crash in case of Client ID reading error, by @HardNorth
8+
9+
## [5.3.2]
410
### Fixed
511
- Client crash in case of Client ID saving error, by @HardNorth
612

reportportal_client/client.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ def __init__(self,
9898
self.log_batch_payload_size = log_batch_payload_size
9999
self.token = token
100100
self.verify_ssl = verify_ssl
101+
self.retries = retries
102+
self.max_pool_size = max_pool_size
101103
self.http_timeout = http_timeout
102104
self.session = requests.Session()
103105
self.step_reporter = StepReporter(self)
@@ -167,7 +169,7 @@ def finish_test_item(self,
167169
"""Finish suite/case/step/nested step item.
168170
169171
:param item_id: ID of the test item
170-
:param end_time: Test item end time
172+
:param end_time: The item end time
171173
:param status: Test status. Allowable values: "passed",
172174
"failed", "stopped", "skipped", "interrupted",
173175
"cancelled" or None
@@ -197,7 +199,6 @@ def finish_test_item(self,
197199
verify_ssl=self.verify_ssl).make()
198200
if not response:
199201
return
200-
# noinspection PyUnresolvedReferences
201202
self._item_stack.pop() if len(self._item_stack) > 0 else None
202203
logger.debug('finish_test_item - ID: %s', item_id)
203204
logger.debug('response message: %s', response.message)
@@ -281,9 +282,9 @@ def log(self, time, message, level=None, attachment=None, item_id=None):
281282
"""Send log message to the Report Portal.
282283
283284
:param time: Time in UTC
284-
:param message: Log message
285+
:param message: Log message text
285286
:param level: Message's log level
286-
:param attachment: Message attachments
287+
:param attachment: Message's attachments
287288
:param item_id: ID of the RP item the message belongs to
288289
"""
289290
self._log_manager.log(time, message, level, attachment, item_id)
@@ -370,7 +371,7 @@ def start_test_item(self,
370371
"""Start case/step/nested step item.
371372
372373
:param name: Name of the test item
373-
:param start_time: Test item start time
374+
:param start_time: The item start time
374375
:param item_type: Type of the test item. Allowable values:
375376
"suite", "story", "test", "scenario", "step",
376377
"before_class", "before_groups",
@@ -379,7 +380,7 @@ def start_test_item(self,
379380
"after_method", "after_suite", "after_test"
380381
:param attributes: Test item attributes
381382
:param code_ref: Physical location of the test item
382-
:param description: Test item description
383+
:param description: The item description
383384
:param has_stats: Set to False if test item is nested step
384385
:param parameters: Set of parameters (for parametrized test items)
385386
:param parent_item_id: An ID of a parent SUITE / STEP
@@ -418,7 +419,6 @@ def start_test_item(self,
418419
item_id = response.id
419420
if item_id is not NOT_FOUND:
420421
logger.debug('start_test_item - ID: %s', item_id)
421-
# noinspection PyUnresolvedReferences
422422
self._item_stack.append(item_id)
423423
else:
424424
logger.warning('start_test_item - invalid response: %s',
@@ -452,5 +452,29 @@ def update_test_item(self, item_uuid, attributes=None, description=None):
452452

453453
def current_item(self):
454454
"""Retrieve the last item reported by the client."""
455-
# noinspection PyUnresolvedReferences
456455
return self._item_stack[-1] if len(self._item_stack) > 0 else None
456+
457+
def clone(self):
458+
"""Clone the client object, set current Item ID as cloned item ID.
459+
460+
:returns: Cloned client object
461+
:rtype: RPClient
462+
"""
463+
cloned = RPClient(
464+
endpoint=self.endpoint,
465+
project=self.project,
466+
token=self.token,
467+
log_batch_size=self.log_batch_size,
468+
is_skipped_an_issue=self.is_skipped_an_issue,
469+
verify_ssl=self.verify_ssl,
470+
retries=self.retries,
471+
max_pool_size=self.max_pool_size,
472+
launch_id=self.launch_id,
473+
http_timeout=self.http_timeout,
474+
log_batch_payload_size=self.log_batch_payload_size,
475+
mode=self.mode
476+
)
477+
current_item = self.current_item()
478+
if current_item:
479+
cloned._item_stack.append(current_item)
480+
return cloned

reportportal_client/client.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ class RPClient:
2424
project: Text = ...
2525
token: Text = ...
2626
verify_ssl: bool = ...
27+
retries: int = ...
28+
max_pool_size: int = ...
2729
http_timeout: Union[float, Tuple[float, float]] = ...
2830
session: Session = ...
2931
step_reporter: StepReporter = ...
3032
mode: str = ...
3133
_skip_analytics: Text = ...
34+
_item_stack: List[Text] = ...
3235

3336
def __init__(
3437
self,
@@ -41,7 +44,8 @@ class RPClient:
4144
max_pool_size: int = ...,
4245
launch_id: Text = ...,
4346
http_timeout: Union[float, Tuple[float, float]] = ...,
44-
log_batch_payload_size: int = ...
47+
log_batch_payload_size: int = ...,
48+
mode: str = ...
4549
) -> None: ...
4650

4751
def finish_launch(self,
@@ -106,3 +110,5 @@ class RPClient:
106110
def current_item(self) -> Text: ...
107111

108112
def start(self) -> None : ...
113+
114+
def clone(self) -> RPClient: ...

reportportal_client/services/client_id.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ def _store_client_id(client_id):
7979

8080
def get_client_id():
8181
"""Return unique client ID of the instance, generate new if not exists."""
82-
client_id = _read_client_id()
82+
client_id = None
83+
try:
84+
client_id = _read_client_id()
85+
except (PermissionError, IOError) as error:
86+
logger.exception('[%s] Unknown exception has occurred. '
87+
'Skipping client ID reading.', error)
8388
if not client_id:
8489
client_id = str(uuid4())
8590
try:

reportportal_client/services/statistics.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def send_event(event_name, agent_name, agent_version):
5454
:param agent_version: Version of the agent
5555
"""
5656
client_name, client_version = _get_client_info()
57-
params = {
57+
request_params = {
5858
'client_name': client_name,
5959
'client_version': client_version,
6060
'interpreter': _get_platform_info(),
@@ -63,24 +63,24 @@ def send_event(event_name, agent_name, agent_version):
6363
}
6464

6565
if agent_name:
66-
params['agent_name'] = agent_name
66+
request_params['agent_name'] = agent_name
6767
if agent_version:
68-
params['agent_version'] = agent_version
68+
request_params['agent_version'] = agent_version
6969

7070
payload = {
7171
'client_id': get_client_id(),
7272
'events': [{
7373
'name': event_name,
74-
'params': params
74+
'params': request_params
7575
}]
7676
}
7777
headers = {'User-Agent': 'python-requests'}
78-
params = {
78+
query_params = {
7979
'measurement_id': ID,
8080
'api_secret': KEY
8181
}
8282
try:
8383
return requests.post(url=ENDPOINT, json=payload, headers=headers,
84-
params=params)
84+
params=query_params)
8585
except requests.exceptions.RequestException as err:
8686
logger.debug('Failed to send data to Statistics service: %s', str(err))

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
aenum
22
delayed_assert
3-
requests>=2.23.0
4-
six>=1.15.0
3+
requests>=2.27.1
4+
six>=1.16.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from setuptools import setup, find_packages
66

7-
__version__ = '5.3.2'
7+
__version__ = '5.3.3'
88

99
TYPE_STUBS = ['*.pyi']
1010

tests/test_client.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,30 @@ def test_statistics(send_event, getenv):
139139
client.session = mock.Mock()
140140
client.start_launch('Test Launch', timestamp())
141141
assert mock.call('start_launch', None, None) in send_event.mock_calls
142+
143+
144+
def test_clone():
145+
args = ['http://endpoint', 'project', 'token']
146+
kwargs = {'log_batch_size': 30, 'is_skipped_an_issue': False,
147+
'verify_ssl': False, 'retries': 5,
148+
'max_pool_size': 30, 'launch_id': 'test-123',
149+
'http_timeout': (30, 30),
150+
'log_batch_payload_size': 1000000, 'mode': 'DEBUG'}
151+
client = RPClient(*args, **kwargs)
152+
client._item_stack.append('test-321')
153+
client._item_stack.append('test-322')
154+
cloned = client.clone()
155+
assert cloned is not None and client is not cloned
156+
assert cloned.endpoint == args[0] and cloned.project == args[
157+
1] and cloned.token == args[2]
158+
assert cloned.log_batch_size == kwargs[
159+
'log_batch_size'] and cloned.is_skipped_an_issue == kwargs[
160+
'is_skipped_an_issue'] and cloned.verify_ssl == kwargs[
161+
'verify_ssl'] and cloned.retries == kwargs[
162+
'retries'] and cloned.max_pool_size == kwargs[
163+
'max_pool_size'] and cloned.launch_id == kwargs[
164+
'launch_id'] and cloned.http_timeout == kwargs[
165+
'http_timeout'] and cloned.log_batch_payload_size == kwargs[
166+
'log_batch_payload_size'] and cloned.mode == kwargs['mode']
167+
assert len(cloned._item_stack) == 1 \
168+
and client.current_item() == cloned.current_item()

0 commit comments

Comments
 (0)