@@ -208,16 +208,16 @@ async def close(self) -> None:
208
208
await self ._session .close ()
209
209
self ._session = None
210
210
211
- async def __get_item_url (self , item_id_future : Union [str , Task [str ]]) -> Optional [str ]:
211
+ async def __get_item_url (self , item_id_future : Union [Optional [ str ] , Task [Optional [ str ] ]]) -> Optional [str ]:
212
212
item_id = await await_if_necessary (item_id_future )
213
- if item_id is NOT_FOUND :
213
+ if item_id is NOT_FOUND or item_id is None :
214
214
logger .warning ('Attempt to make request for non-existent id.' )
215
215
return
216
216
return root_uri_join (self .base_url_v2 , 'item' , item_id )
217
217
218
- async def __get_launch_url (self , launch_uuid_future : Union [str , Task [str ]]) -> Optional [str ]:
218
+ async def __get_launch_url (self , launch_uuid_future : Union [Optional [ str ] , Task [Optional [ str ] ]]) -> Optional [str ]:
219
219
launch_uuid = await await_if_necessary (launch_uuid_future )
220
- if launch_uuid is NOT_FOUND :
220
+ if launch_uuid is NOT_FOUND or launch_uuid is None :
221
221
logger .warning ('Attempt to make request for non-existent launch.' )
222
222
return
223
223
return root_uri_join (self .base_url_v2 , 'launch' , launch_uuid , 'finish' )
@@ -442,7 +442,7 @@ async def update_test_item(self,
442
442
443
443
async def __get_launch_uuid_url (self , launch_uuid_future : Union [str , Task [str ]]) -> Optional [str ]:
444
444
launch_uuid = await await_if_necessary (launch_uuid_future )
445
- if launch_uuid is NOT_FOUND :
445
+ if launch_uuid is NOT_FOUND or launch_uuid is None :
446
446
logger .warning ('Attempt to make request for non-existent Launch UUID.' )
447
447
return
448
448
logger .debug ('get_launch_info - ID: %s' , launch_uuid )
@@ -466,9 +466,9 @@ async def get_launch_info(self, launch_uuid_future: Union[str, Task[str]]) -> Op
466
466
logger .warning ('get_launch_info - Launch info: Failed to fetch launch ID from the API.' )
467
467
return launch_info
468
468
469
- async def __get_item_uuid_url (self , item_uuid_future : Union [str , Task [str ]]) -> Optional [str ]:
469
+ async def __get_item_uuid_url (self , item_uuid_future : Union [Optional [ str ] , Task [Optional [ str ] ]]) -> Optional [str ]:
470
470
item_uuid = await await_if_necessary (item_uuid_future )
471
- if item_uuid is NOT_FOUND :
471
+ if item_uuid is NOT_FOUND or item_uuid is None :
472
472
logger .warning ('Attempt to make request for non-existent UUID.' )
473
473
return
474
474
return root_uri_join (self .base_url_v1 , 'item' , 'uuid' , item_uuid )
@@ -972,7 +972,7 @@ def client(self) -> Client:
972
972
return self .__client
973
973
974
974
@property
975
- def launch_uuid (self ) -> Optional [ Task [str ]]:
975
+ def launch_uuid (self ) -> Task [ Optional [str ]]:
976
976
"""Return current Launch UUID.
977
977
978
978
:return: UUID string.
@@ -1102,13 +1102,13 @@ def current_item(self) -> Task[_T]:
1102
1102
"""
1103
1103
return self ._item_stack .last ()
1104
1104
1105
- async def __empty_str (self ):
1105
+ async def __empty_str (self ) -> str :
1106
1106
return ""
1107
1107
1108
- async def __empty_dict (self ):
1108
+ async def __empty_dict (self ) -> dict :
1109
1109
return {}
1110
1110
1111
- async def __int_value (self ):
1111
+ async def __int_value (self ) -> int :
1112
1112
return - 1
1113
1113
1114
1114
def start_launch (self ,
@@ -1118,7 +1118,7 @@ def start_launch(self,
1118
1118
attributes : Optional [Union [list , dict ]] = None ,
1119
1119
rerun : bool = False ,
1120
1120
rerun_of : Optional [str ] = None ,
1121
- ** kwargs ) -> Task [str ]:
1121
+ ** kwargs ) -> Task [Optional [ str ] ]:
1122
1122
"""Start a new Launch with the given arguments.
1123
1123
1124
1124
:param name: Launch name.
@@ -1151,7 +1151,7 @@ def start_test_item(self,
1151
1151
retry : bool = False ,
1152
1152
test_case_id : Optional [str ] = None ,
1153
1153
retry_of : Optional [str ] = None ,
1154
- ** kwargs : Any ) -> Task [str ]:
1154
+ ** kwargs : Any ) -> Task [Optional [ str ] ]:
1155
1155
"""Start Test Case/Suite/Step/Nested Step Item.
1156
1156
1157
1157
:param name: Name of the Test Item.
@@ -1191,7 +1191,7 @@ def finish_test_item(self,
1191
1191
retry : bool = False ,
1192
1192
test_case_id : Optional [str ] = None ,
1193
1193
retry_of : Optional [str ] = None ,
1194
- ** kwargs : Any ) -> Task [str ]:
1194
+ ** kwargs : Any ) -> Task [Optional [ str ] ]:
1195
1195
"""Finish Test Suite/Case/Step/Nested Step Item.
1196
1196
1197
1197
:param item_id: ID of the Test Item.
@@ -1219,7 +1219,7 @@ def finish_launch(self,
1219
1219
end_time : str ,
1220
1220
status : Optional [str ] = None ,
1221
1221
attributes : Optional [Union [list , dict ]] = None ,
1222
- ** kwargs : Any ) -> Task [str ]:
1222
+ ** kwargs : Any ) -> Task [Optional [ str ] ]:
1223
1223
"""Finish a Launch.
1224
1224
1225
1225
:param end_time: Launch end time.
@@ -1242,7 +1242,7 @@ def finish_launch(self,
1242
1242
def update_test_item (self ,
1243
1243
item_uuid : Task [str ],
1244
1244
attributes : Optional [Union [list , dict ]] = None ,
1245
- description : Optional [str ] = None ) -> Task :
1245
+ description : Optional [str ] = None ) -> Task [ Optional [ str ]] :
1246
1246
"""Update existing Test Item at the ReportPortal.
1247
1247
1248
1248
:param item_uuid: Test Item UUID returned on the item start.
@@ -1255,7 +1255,7 @@ def update_test_item(self,
1255
1255
result_task = self .create_task (result_coro )
1256
1256
return result_task
1257
1257
1258
- def get_launch_info (self ) -> Task [dict ]:
1258
+ def get_launch_info (self ) -> Task [Optional [ dict ] ]:
1259
1259
"""Get current Launch information.
1260
1260
1261
1261
:return: Launch information in dictionary.
@@ -1266,7 +1266,7 @@ def get_launch_info(self) -> Task[dict]:
1266
1266
result_task = self .create_task (result_coro )
1267
1267
return result_task
1268
1268
1269
- def get_item_id_by_uuid (self , item_uuid_future : Task [str ]) -> Task [str ]:
1269
+ def get_item_id_by_uuid (self , item_uuid_future : Task [Optional [ str ]] ) -> Task [Optional [ str ] ]:
1270
1270
"""Get Test Item ID by the given Item UUID.
1271
1271
1272
1272
:param item_uuid_future: Str or Task UUID returned on the Item start.
@@ -1276,7 +1276,7 @@ def get_item_id_by_uuid(self, item_uuid_future: Task[str]) -> Task[str]:
1276
1276
result_task = self .create_task (result_coro )
1277
1277
return result_task
1278
1278
1279
- def get_launch_ui_id (self ) -> Task [int ]:
1279
+ def get_launch_ui_id (self ) -> Task [Optional [ int ] ]:
1280
1280
"""Get Launch ID of the current Launch.
1281
1281
1282
1282
:return: Launch ID of the Launch. None if not found.
@@ -1287,7 +1287,7 @@ def get_launch_ui_id(self) -> Task[int]:
1287
1287
result_task = self .create_task (result_coro )
1288
1288
return result_task
1289
1289
1290
- def get_launch_ui_url (self ) -> Task [str ]:
1290
+ def get_launch_ui_url (self ) -> Task [Optional [ str ] ]:
1291
1291
"""Get full quality URL of the current Launch.
1292
1292
1293
1293
:return: Launch URL string.
@@ -1298,7 +1298,7 @@ def get_launch_ui_url(self) -> Task[str]:
1298
1298
result_task = self .create_task (result_coro )
1299
1299
return result_task
1300
1300
1301
- def get_project_settings (self ) -> Task [dict ]:
1301
+ def get_project_settings (self ) -> Task [Optional [ str ] ]:
1302
1302
"""Get settings of the current Project.
1303
1303
1304
1304
:return: Settings response in Dictionary.
@@ -1314,7 +1314,7 @@ async def _log(self, log_rq: AsyncRPRequestLog) -> Optional[Tuple[str, ...]]:
1314
1314
return await self ._log_batch (await self ._log_batcher .append_async (log_rq ))
1315
1315
1316
1316
def log (self , time : str , message : str , level : Optional [Union [int , str ]] = None ,
1317
- attachment : Optional [dict ] = None , item_id : Optional [Task [str ]] = None ) -> Task [Tuple [str , ...]]:
1317
+ attachment : Optional [dict ] = None , item_id : Optional [Task [str ]] = None ) -> Task [Optional [ Tuple [str , ...] ]]:
1318
1318
"""Send Log message to the ReportPortal and attach it to a Test Item or Launch.
1319
1319
1320
1320
This method stores Log messages in internal batch and sent it when batch is full, so not every method
@@ -1338,6 +1338,11 @@ def close(self) -> None:
1338
1338
self .create_task (self .__client .close ()).blocking_result ()
1339
1339
1340
1340
1341
+ def heartbeat (self ):
1342
+ """Heartbeat function to keep the loop running."""
1343
+ self ._loop .call_at (self ._loop .time () + 0.1 , heartbeat , self )
1344
+
1345
+
1341
1346
class ThreadedRPClient (_RPClient ):
1342
1347
"""Synchronous-asynchronous ReportPortal Client which uses background Thread to execute async coroutines.
1343
1348
@@ -1369,7 +1374,7 @@ def __init_task_list(self, task_list: Optional[BackgroundTaskList[Task[_T]]] = N
1369
1374
def __heartbeat (self ):
1370
1375
# We operate on our own loop with daemon thread, so we will exit in any way when main thread exit,
1371
1376
# so we can iterate forever
1372
- self . _loop . call_at (self . _loop . time () + 0.1 , self . __heartbeat )
1377
+ heartbeat (self )
1373
1378
1374
1379
def __init_loop (self , loop : Optional [asyncio .AbstractEventLoop ] = None ):
1375
1380
self ._thread = None
@@ -1471,6 +1476,8 @@ def finish_tasks(self):
1471
1476
break
1472
1477
logs = self ._log_batcher .flush ()
1473
1478
if logs :
1479
+ # We use own Task Factory in which we add the following method to the Task class
1480
+ # noinspection PyUnresolvedReferences
1474
1481
self ._loop .create_task (self ._log_batch (logs )).blocking_result ()
1475
1482
1476
1483
def clone (self ) -> 'ThreadedRPClient' :
0 commit comments