Skip to content

Commit 5a1b853

Browse files
committed
Add launch_uuid_print and print_output arguments in RPClient class constructor
1 parent 6e7a805 commit 5a1b853

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
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+
- `launch_uuid_print` and `print_output` arguments in `RPClient` class constructor, by @HardNorth
46

57
## [5.3.5]
68
### Added

reportportal_client/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
# limitations under the License
1515

1616
import logging
17+
import sys
1718
import warnings
1819
from os import getenv
19-
from typing import Union, Tuple, List, Dict, Any, Optional
20+
from typing import Union, Tuple, List, Dict, Any, Optional, TextIO
2021

2122
import requests
2223
from requests.adapters import HTTPAdapter, Retry, DEFAULT_RETRIES
@@ -70,6 +71,8 @@ class RPClient:
7071
session: requests.Session = ...
7172
step_reporter: StepReporter = ...
7273
mode: str = ...
74+
launch_uuid_print: Optional[bool] = ...
75+
print_output: Optional[TextIO] = ...
7376
_skip_analytics: str = ...
7477
_item_stack: List[str] = ...
7578

@@ -87,6 +90,8 @@ def __init__(
8790
http_timeout: Union[float, Tuple[float, float]] = (10, 10),
8891
log_batch_payload_size: int = MAX_LOG_BATCH_PAYLOAD_SIZE,
8992
mode: str = 'DEFAULT',
93+
launch_uuid_print: bool = False,
94+
print_output: TextIO = sys.stdout,
9095
**kwargs: Any
9196
) -> None:
9297
"""Initialize required attributes.
@@ -131,6 +136,8 @@ def __init__(
131136
self._item_stack = []
132137
self.mode = mode
133138
self._skip_analytics = getenv('AGENT_NO_ANALYTICS')
139+
self.launch_uuid_print = launch_uuid_print
140+
self.print_output = print_output
134141

135142
self.api_key = api_key
136143
if not self.api_key:
@@ -414,6 +421,8 @@ def start_launch(self,
414421

415422
self._log_manager.launch_id = self.launch_id = response.id
416423
logger.debug('start_launch - ID: %s', self.launch_id)
424+
if self.launch_uuid_print and self.print_output:
425+
print(f'Report Portal Launch UUID: {self.launch_id}', file=self.print_output)
417426
return self.launch_id
418427

419428
def start_test_item(self,

tests/test_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License
13+
from io import StringIO
1314

1415
import pytest
1516
from requests import Response
@@ -196,3 +197,13 @@ def test_empty_api_key_argument(warn):
196197

197198
assert warn.call_count == 1
198199
assert client.api_key == api_key
200+
201+
202+
def test_launch_uuid_print():
203+
str_io = StringIO()
204+
client = RPClient(endpoint='http://endpoint', project='project',
205+
api_key='test', launch_uuid_print=True, print_output=str_io)
206+
client.session = mock.Mock()
207+
client._skip_analytics = True
208+
client.start_launch('Test Launch', timestamp())
209+
assert 'Report Portal Launch UUID: ' in str_io.getvalue()

0 commit comments

Comments
 (0)