2020import threading
2121import traceback
2222from collections import OrderedDict
23+ from datetime import datetime , timezone
2324from enum import Enum
2425from functools import wraps
2526from os import curdir
3132from pytest import Class , Function , Item , Module , Package , Session
3233from reportportal_client .aio import Task
3334from reportportal_client .core .rp_issues import ExternalIssue , Issue
34- from reportportal_client .helpers import markdown_helpers , timestamp
35+ from reportportal_client .helpers import markdown_helpers
3536
3637from .config import AgentConfig
3738
@@ -236,7 +237,7 @@ def _build_start_launch_rq(self) -> dict[str, Any]:
236237 start_rq = {
237238 "attributes" : self ._get_launch_attributes (attributes ),
238239 "name" : self ._config .rp_launch ,
239- "start_time" : timestamp ( ),
240+ "start_time" : datetime . now ( tz = timezone . utc ),
240241 "description" : self ._config .rp_launch_description ,
241242 "rerun" : self ._config .rp_rerun ,
242243 "rerun_of" : self ._config .rp_rerun_of ,
@@ -565,7 +566,7 @@ def _build_start_suite_rq(self, leaf: dict[str, Any]) -> dict[str, Any]:
565566 payload = {
566567 "name" : leaf ["name" ],
567568 "description" : self ._get_item_description (item ),
568- "start_time" : timestamp ( ),
569+ "start_time" : datetime . now ( tz = timezone . utc ),
569570 "item_type" : "SUITE" ,
570571 "code_ref" : code_ref ,
571572 "parent_item_id" : parent_item_id ,
@@ -867,7 +868,7 @@ def _build_start_step_rq(self, leaf: dict[str, Any]) -> dict[str, Any]:
867868 "attributes" : leaf .get ("attributes" , None ),
868869 "name" : leaf ["name" ],
869870 "description" : leaf ["description" ],
870- "start_time" : timestamp ( ),
871+ "start_time" : datetime . now ( tz = timezone . utc ),
871872 "item_type" : "STEP" ,
872873 "code_ref" : leaf .get ("code_ref" , None ),
873874 "parameters" : leaf .get ("parameters" , None ),
@@ -946,7 +947,7 @@ def _build_finish_step_rq(self, leaf: dict[str, Any]) -> dict[str, Any]:
946947 issue = None
947948 payload = {
948949 "attributes" : leaf .get ("attributes" , None ),
949- "end_time" : timestamp ( ),
950+ "end_time" : datetime . now ( tz = timezone . utc ),
950951 "status" : status ,
951952 "issue" : issue ,
952953 "item_id" : leaf ["item_id" ],
@@ -962,7 +963,7 @@ def _finish_suite(self, finish_rq: dict[str, Any]) -> None:
962963 self .rp .finish_test_item (** finish_rq )
963964
964965 def _build_finish_suite_rq (self , leaf ) -> dict [str , Any ]:
965- payload = {"end_time" : timestamp ( ), "item_id" : leaf ["item_id" ]}
966+ payload = {"end_time" : datetime . now ( tz = timezone . utc ), "item_id" : leaf ["item_id" ]}
966967 return payload
967968
968969 def _proceed_suite_finish (self , leaf ) -> None :
@@ -1039,7 +1040,7 @@ def finish_suites(self) -> None:
10391040 self ._lock (leaf , lambda p : self ._proceed_suite_finish (p ))
10401041
10411042 def _build_finish_launch_rq (self ) -> dict [str , Any ]:
1042- finish_rq = {"end_time" : timestamp ( )}
1043+ finish_rq = {"end_time" : datetime . now ( tz = timezone . utc )}
10431044 return finish_rq
10441045
10451046 def _finish_launch (self , finish_rq ) -> None :
@@ -1057,7 +1058,7 @@ def _build_log(
10571058 ) -> dict [str , Any ]:
10581059 sl_rq = {
10591060 "item_id" : item_id ,
1060- "time" : timestamp ( ),
1061+ "time" : datetime . now ( tz = timezone . utc ),
10611062 "message" : message ,
10621063 "level" : log_level ,
10631064 }
@@ -1106,7 +1107,7 @@ def report_fixture(self, name: str, error_msg: str) -> Generator[None, Any, None
11061107 return
11071108
11081109 reporter = self .rp .step_reporter
1109- item_id = reporter .start_nested_step (name , timestamp ( ))
1110+ item_id = reporter .start_nested_step (name , datetime . now ( tz = timezone . utc ))
11101111
11111112 try :
11121113 outcome = yield
@@ -1123,11 +1124,11 @@ def report_fixture(self, name: str, error_msg: str) -> Generator[None, Any, None
11231124 )
11241125 exception_log = self ._build_log (item_id , traceback_str , log_level = "ERROR" )
11251126 self .rp .log (** exception_log )
1126- reporter .finish_nested_step (item_id , timestamp ( ), status )
1127+ reporter .finish_nested_step (item_id , datetime . now ( tz = timezone . utc ), status )
11271128 except Exception as e :
11281129 LOGGER .error ("Failed to report fixture: %s" , name )
11291130 LOGGER .exception (e )
1130- reporter .finish_nested_step (item_id , timestamp ( ), "FAILED" )
1131+ reporter .finish_nested_step (item_id , datetime . now ( tz = timezone . utc ), "FAILED" )
11311132
11321133 def _get_python_name (self , scenario : Scenario ) -> str :
11331134 python_name = f"test_{ make_python_name (self ._get_scenario_template (scenario ).name )} "
@@ -1284,7 +1285,7 @@ def _finish_bdd_step(self, leaf: dict[str, Any], status: str) -> None:
12841285
12851286 reporter = self .rp .step_reporter
12861287 item_id = leaf ["item_id" ]
1287- reporter .finish_nested_step (item_id , timestamp ( ), status )
1288+ reporter .finish_nested_step (item_id , datetime . now ( tz = timezone . utc ), status )
12881289 leaf ["exec" ] = ExecStatus .FINISHED
12891290
12901291 def _is_background_step (self , step : Step , feature : Feature ) -> bool :
@@ -1326,15 +1327,15 @@ def start_bdd_step(self, feature: Feature, scenario: Scenario, step: Step) -> No
13261327 background_leaf = scenario_leaf ["children" ][feature .background ]
13271328 background_leaf ["children" ][step ] = step_leaf
13281329 if background_leaf ["exec" ] != ExecStatus .IN_PROGRESS :
1329- item_id = reporter .start_nested_step (BACKGROUND_STEP_NAME , timestamp ( ))
1330+ item_id = reporter .start_nested_step (BACKGROUND_STEP_NAME , datetime . now ( tz = timezone . utc ))
13301331 background_leaf ["item_id" ] = item_id
13311332 background_leaf ["exec" ] = ExecStatus .IN_PROGRESS
13321333 else :
13331334 scenario_leaf ["children" ][step ] = step_leaf
13341335 if feature .background :
13351336 background_leaf = scenario_leaf ["children" ][feature .background ]
13361337 self ._finish_bdd_step (background_leaf , "PASSED" )
1337- item_id = reporter .start_nested_step (f"{ step .keyword } { step .name } " , timestamp ( ))
1338+ item_id = reporter .start_nested_step (f"{ step .keyword } { step .name } " , datetime . now ( tz = timezone . utc ))
13381339 step_leaf ["item_id" ] = item_id
13391340 step_leaf ["exec" ] = ExecStatus .IN_PROGRESS
13401341
0 commit comments