Skip to content

Commit 161612d

Browse files
authored
Merge pull request #254 from reportportal/develop
Release
2 parents f648f35 + e0b1387 commit 161612d

File tree

9 files changed

+64
-50
lines changed

9 files changed

+64
-50
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+
### Fixed
5+
- Issue [#246](https://github.com/reportportal/client-Python/issues/246): Invalid return type, by @HardNorth
6+
### Changed
7+
- `helpers.common_helpers.gen_attributes` function now accepts refactored, by @HardNorth
8+
9+
## [5.6.1]
410
### Added
511
- `markdown_helpers` module in `reportportal_client.helpers` package, by @HardNorth
612
### Changed

reportportal_client/_internal/aio/tasks.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from asyncio import Future
2020
from typing import Any, Awaitable, Coroutine, Generator, Generic, List, Optional, TypeVar, Union
2121

22+
from reportportal_client._internal.static.defines import NOT_FOUND
2223
from reportportal_client.aio.tasks import BlockingOperationError, Task
2324

2425
_T = TypeVar("_T")
@@ -54,8 +55,10 @@ def blocking_result(self) -> _T:
5455
:return: execution result or raise an error, or return immediately if already executed
5556
"""
5657
if self.done():
57-
return self.result()
58-
return self.__loop.run_until_complete(self)
58+
result = self.result()
59+
else:
60+
result = self.__loop.run_until_complete(self)
61+
return result if result is not NOT_FOUND else None
5962

6063

6164
class ThreadedTask(Generic[_T], Task[_T]):
@@ -88,7 +91,8 @@ def blocking_result(self) -> _T:
8891
:return: execution result or raise an error, or return immediately if already executed
8992
"""
9093
if self.done():
91-
return self.result()
94+
result = self.result()
95+
return result if result is not NOT_FOUND else None
9296
if not self.__loop.is_running() or self.__loop.is_closed():
9397
raise BlockingOperationError("Running loop is not alive")
9498
start_time = time.time()
@@ -97,7 +101,8 @@ def blocking_result(self) -> _T:
97101
time.sleep(sleep_time)
98102
if not self.done():
99103
raise BlockingOperationError("Timed out waiting for the task execution")
100-
return self.result()
104+
result = self.result()
105+
return result if result is not NOT_FOUND else None
101106

102107

103108
class BatchedTaskFactory:

reportportal_client/aio/client.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ def launch_uuid(self) -> Optional[str]:
639639
640640
:return: UUID string.
641641
"""
642+
if self.__launch_uuid is NOT_FOUND:
643+
return None
642644
return self.__launch_uuid
643645

644646
@property
@@ -750,7 +752,7 @@ async def start_launch(
750752
name, start_time, description=description, attributes=attributes, rerun=rerun, rerun_of=rerun_of, **kwargs
751753
)
752754
self.__launch_uuid = launch_uuid
753-
return launch_uuid
755+
return self.launch_uuid
754756

755757
async def start_test_item(
756758
self,
@@ -791,7 +793,7 @@ async def start_test_item(
791793
:return: Test Item UUID if successfully started or None.
792794
"""
793795
item_id = await self.__client.start_test_item(
794-
self.launch_uuid,
796+
self.__launch_uuid,
795797
name,
796798
start_time,
797799
item_type,
@@ -842,7 +844,7 @@ async def finish_test_item(
842844
:return: Response message.
843845
"""
844846
result = await self.__client.finish_test_item(
845-
self.launch_uuid,
847+
self.__launch_uuid,
846848
item_id,
847849
end_time,
848850
status=status,
@@ -874,7 +876,7 @@ async def finish_launch(
874876
"""
875877
if self.use_own_launch:
876878
result = await self.__client.finish_launch(
877-
self.launch_uuid, end_time, status=status, attributes=attributes, **kwargs
879+
self.__launch_uuid, end_time, status=status, attributes=attributes, **kwargs
878880
)
879881
else:
880882
result = ""
@@ -915,7 +917,7 @@ async def get_launch_info(self) -> Optional[dict]:
915917
"""
916918
if not self.launch_uuid:
917919
return {}
918-
return await self.__client.get_launch_info(self.launch_uuid)
920+
return await self.__client.get_launch_info(self.__launch_uuid)
919921

920922
async def get_item_id_by_uuid(self, item_uuid: str) -> Optional[str]:
921923
"""Get Test Item ID by the given Item UUID.
@@ -932,7 +934,7 @@ async def get_launch_ui_id(self) -> Optional[int]:
932934
"""
933935
if not self.launch_uuid:
934936
return None
935-
return await self.__client.get_launch_ui_id(self.launch_uuid)
937+
return await self.__client.get_launch_ui_id(self.__launch_uuid)
936938

937939
async def get_launch_ui_url(self) -> Optional[str]:
938940
"""Get full quality URL of the current Launch.
@@ -941,7 +943,7 @@ async def get_launch_ui_url(self) -> Optional[str]:
941943
"""
942944
if not self.launch_uuid:
943945
return None
944-
return await self.__client.get_launch_ui_url(self.launch_uuid)
946+
return await self.__client.get_launch_ui_url(self.__launch_uuid)
945947

946948
async def get_project_settings(self) -> Optional[dict]:
947949
"""Get settings of the current Project.
@@ -974,7 +976,7 @@ async def log(
974976
logger.warning("Attempt to log to non-existent item")
975977
return None
976978
rp_file = RPFile(**attachment) if attachment else None
977-
rp_log = AsyncRPRequestLog(self.launch_uuid, time, rp_file, item_id, level, message)
979+
rp_log = AsyncRPRequestLog(self.__launch_uuid, time, rp_file, item_id, level, message)
978980
return await self.__client.log_batch(await self._log_batcher.append_async(rp_log))
979981

980982
def clone(self) -> "AsyncRPClient":
@@ -989,7 +991,7 @@ def clone(self) -> "AsyncRPClient":
989991
endpoint=self.endpoint,
990992
project=self.project,
991993
client=cloned_client,
992-
launch_uuid=self.launch_uuid,
994+
launch_uuid=self.__launch_uuid,
993995
log_batch_size=self.log_batch_size,
994996
log_batch_payload_limit=self.log_batch_payload_limit,
995997
log_batcher=self._log_batcher,
@@ -1017,7 +1019,7 @@ class _RPClient(RP, metaclass=AbstractBaseClass):
10171019
_item_stack: LifoQueue
10181020
_log_batcher: LogBatcher
10191021
__client: Client
1020-
__launch_uuid: Optional[Task[str]]
1022+
__launch_uuid: Optional[Task[Optional[str]]]
10211023
__endpoint: str
10221024
__project: str
10231025
__step_reporter: StepReporter
@@ -1031,7 +1033,7 @@ def client(self) -> Client:
10311033
return self.__client
10321034

10331035
@property
1034-
def launch_uuid(self) -> Task[Optional[str]]:
1036+
def launch_uuid(self) -> Optional[Task[Optional[str]]]:
10351037
"""Return current Launch UUID.
10361038
10371039
:return: UUID string.
@@ -1068,7 +1070,7 @@ def __init__(
10681070
project: str,
10691071
*,
10701072
client: Optional[Client] = None,
1071-
launch_uuid: Optional[Task[str]] = None,
1073+
launch_uuid: Optional[Task[Optional[str]]] = None,
10721074
log_batch_size: int = 20,
10731075
log_batch_payload_limit: int = MAX_LOG_BATCH_PAYLOAD_SIZE,
10741076
log_batcher: Optional[LogBatcher] = None,

reportportal_client/client.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ def launch_uuid(self) -> Optional[str]:
408408
409409
:return: UUID string
410410
"""
411+
if self.__launch_uuid is NOT_FOUND:
412+
return None
411413
return self.__launch_uuid
412414

413415
@property
@@ -593,9 +595,9 @@ def start_launch(
593595
send_event("start_launch", *agent_name_version(attributes))
594596

595597
self.__launch_uuid = response.id
596-
logger.debug("start_launch - ID: %s", self.launch_uuid)
598+
logger.debug("start_launch - ID: %s", self.__launch_uuid)
597599
if self.launch_uuid_print and self.print_output:
598-
print(f"ReportPortal Launch UUID: {self.launch_uuid}", file=self.print_output.get_output())
600+
print(f"ReportPortal Launch UUID: {self.__launch_uuid}", file=self.print_output.get_output())
599601
return self.launch_uuid
600602

601603
def start_test_item(
@@ -647,7 +649,7 @@ def start_test_item(
647649
name,
648650
start_time,
649651
item_type,
650-
self.launch_uuid,
652+
self.__launch_uuid,
651653
attributes=verify_value_length(attributes) if self.truncate_attributes else attributes,
652654
code_ref=code_ref,
653655
description=description,
@@ -711,7 +713,7 @@ def finish_test_item(
711713
url = uri_join(self.base_url_v2, "item", item_id)
712714
request_payload = ItemFinishRequest(
713715
end_time,
714-
self.launch_uuid,
716+
self.__launch_uuid,
715717
status,
716718
attributes=verify_value_length(attributes) if self.truncate_attributes else attributes,
717719
description=description,
@@ -746,10 +748,10 @@ def finish_launch(
746748
:param attributes: Launch attributes
747749
"""
748750
if self.use_own_launch:
749-
if self.launch_uuid is NOT_FOUND or not self.launch_uuid:
751+
if self.__launch_uuid is NOT_FOUND or not self.__launch_uuid:
750752
logger.warning("Attempt to finish non-existent launch")
751753
return None
752-
url = uri_join(self.base_url_v2, "launch", self.launch_uuid, "finish")
754+
url = uri_join(self.base_url_v2, "launch", self.__launch_uuid, "finish")
753755
request_payload = LaunchFinishRequest(
754756
end_time,
755757
status=status,
@@ -766,7 +768,7 @@ def finish_launch(
766768
).make()
767769
if not response:
768770
return None
769-
logger.debug("finish_launch - ID: %s", self.launch_uuid)
771+
logger.debug("finish_launch - ID: %s", self.__launch_uuid)
770772
logger.debug("response message: %s", response.message)
771773
message = response.message
772774
else:
@@ -835,7 +837,7 @@ def log(
835837
logger.warning("Attempt to log to non-existent item")
836838
return None
837839
rp_file = RPFile(**attachment) if attachment else None
838-
rp_log = RPRequestLog(self.launch_uuid, time, rp_file, item_id, level, message)
840+
rp_log = RPRequestLog(self.__launch_uuid, time, rp_file, item_id, level, message)
839841
return self._log(self._log_batcher.append(rp_log))
840842

841843
def get_item_id_by_uuid(self, item_uuid: str) -> Optional[str]:
@@ -857,8 +859,8 @@ def get_launch_info(self) -> Optional[dict]:
857859
"""
858860
if self.launch_uuid is None:
859861
return {}
860-
url = uri_join(self.base_url_v1, "launch", "uuid", self.launch_uuid)
861-
logger.debug("get_launch_info - ID: %s", self.launch_uuid)
862+
url = uri_join(self.base_url_v1, "launch", "uuid", self.__launch_uuid)
863+
logger.debug("get_launch_info - ID: %s", self.__launch_uuid)
862864
response = HttpRequest(
863865
self.session.get, url=url, verify_ssl=self.verify_ssl, http_timeout=self.http_timeout
864866
).make()
@@ -899,7 +901,7 @@ def get_launch_ui_url(self) -> Optional[str]:
899901
project_name=self.__project.lower(), launch_type=launch_type, launch_id=ui_id
900902
)
901903
url = uri_join(self.__endpoint, path)
902-
logger.debug("get_launch_ui_url - UUID: %s", self.launch_uuid)
904+
logger.debug("get_launch_ui_url - UUID: %s", self.__launch_uuid)
903905
return url
904906

905907
def get_project_settings(self) -> Optional[dict]:
@@ -949,7 +951,7 @@ def clone(self) -> "RPClient":
949951
verify_ssl=self.verify_ssl,
950952
retries=self.retries,
951953
max_pool_size=self.max_pool_size,
952-
launch_uuid=self.launch_uuid,
954+
launch_uuid=self.__launch_uuid,
953955
http_timeout=self.http_timeout,
954956
log_batch_payload_size=self.log_batch_payload_size,
955957
mode=self.mode,

reportportal_client/core/rp_requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ async def make(self) -> Optional[AsyncRPResponse]:
173173
"""
174174
url = await await_if_necessary(self.url)
175175
if not url:
176-
return
176+
return None
177177
data = await await_if_necessary(self.data)
178178
json = await await_if_necessary(self.json)
179179
try:

reportportal_client/core/rp_responses.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def id(self) -> Optional[str]:
7070
:return: ID as string or NOT_FOUND, or None if the response is not JSON
7171
"""
7272
if self.json is None:
73-
return
73+
return None
7474
return self.json.get("id", NOT_FOUND)
7575

7676
@property
@@ -102,7 +102,7 @@ def message(self) -> Optional[str]:
102102
:return: message as string or NOT_FOUND, or None if the response is not JSON
103103
"""
104104
if self.json is None:
105-
return
105+
return None
106106
return self.json.get("message")
107107

108108
@property
@@ -112,7 +112,7 @@ def messages(self) -> Optional[Tuple[str, ...]]:
112112
:return: a variable size tuple of strings or NOT_FOUND, or None if the response is not JSON
113113
"""
114114
if self.json is None:
115-
return
115+
return None
116116
return tuple(_iter_json_messages(self.json))
117117

118118

@@ -138,7 +138,7 @@ async def id(self) -> Optional[str]:
138138
"""
139139
json = await self.json
140140
if json is None:
141-
return
141+
return None
142142
return json.get("id", NOT_FOUND)
143143

144144
@property
@@ -171,7 +171,7 @@ async def message(self) -> Optional[str]:
171171
"""
172172
json = await self.json
173173
if json is None:
174-
return
174+
return None
175175
return json.get("message", NOT_FOUND)
176176

177177
@property
@@ -182,5 +182,5 @@ async def messages(self) -> Optional[Tuple[str, ...]]:
182182
"""
183183
json = await self.json
184184
if json is None:
185-
return
185+
return None
186186
return tuple(_iter_json_messages(json))

reportportal_client/helpers/common_helpers.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
ATTRIBUTE_LENGTH_LIMIT: int = 128
4040
TRUNCATE_REPLACEMENT: str = "..."
4141
BYTES_TO_READ_FOR_DETECTION = 128
42+
ATTRIBUTE_DELIMITER = ":"
4243

4344
CONTENT_TYPE_TO_EXTENSIONS = MappingProxyType(
4445
{
@@ -167,20 +168,18 @@ def gen_attributes(rp_attributes: Iterable[str]) -> List[Dict[str, str]]:
167168
:return: Correctly created list of dictionaries
168169
to be passed to RP
169170
"""
170-
attrs = []
171-
for rp_attr in rp_attributes:
172-
try:
173-
key, value = rp_attr.split(":")
174-
attr_dict = {"key": key, "value": value}
175-
except ValueError as exc:
176-
logger.debug(str(exc))
177-
attr_dict = {"value": rp_attr}
178-
179-
if all(attr_dict.values()):
180-
attrs.append(attr_dict)
171+
attributes = []
172+
for attr in rp_attributes:
173+
if not attr:
181174
continue
182-
logger.debug(f'Failed to process "{rp_attr}" attribute, attribute value should not be empty.')
183-
return attrs
175+
value = attr
176+
if ATTRIBUTE_DELIMITER in attr:
177+
key, value = attr.split(ATTRIBUTE_DELIMITER, 1)
178+
attribute = {"key": key, "value": value}
179+
else:
180+
attribute = {"value": value}
181+
attributes.append(attribute)
182+
return attributes
184183

185184

186185
def get_launch_sys_attrs() -> Dict[str, str]:

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 find_packages, setup
66

7-
__version__ = "5.6.1"
7+
__version__ = "5.6.2"
88

99
TYPE_STUBS = ["*.pyi"]
1010

tests/helpers/test_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_gen_attributes():
3636
"""Test functionality of the gen_attributes function."""
3737
expected_out = [{"value": "Tag"}, {"key": "Key", "value": "Value"}]
3838
out = gen_attributes(["Tag", "Key:Value", ""])
39-
assert expected_out == out
39+
assert out == expected_out
4040

4141

4242
@mock.patch("reportportal_client.helpers.common_helpers.system", mock.Mock(return_value="linux"))

0 commit comments

Comments
 (0)