Skip to content

Commit 0e1e883

Browse files
committed
RPClient.clone() method
1 parent 57ec486 commit 0e1e883

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

CHANGELOG.md

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

33
## [Unreleased]
4+
### Added
5+
- `RPClient.clone()` method, by @HardNorth
46
### Fixed
57
- Client crash in case of Client ID reading error, by @HardNorth
68

reportportal_client/client.py

Lines changed: 31 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,28 @@ 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 current client, set current item ID as cloned object 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)

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: ...

0 commit comments

Comments
 (0)