Skip to content

Commit

Permalink
Convert the generated time to datetime ISO string
Browse files Browse the repository at this point in the history
  • Loading branch information
seberm committed Nov 12, 2024
1 parent c8edf27 commit fcb9d72
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tmt/steps/report/reportportal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dataclasses
import datetime
import os
import re
from time import time
from typing import TYPE_CHECKING, Any, Optional, overload

import requests
Expand All @@ -12,7 +12,6 @@
from tmt.result import ResultOutcome
from tmt.utils import field, yaml_to_dict


if TYPE_CHECKING:
from tmt._compat.typing import TypeAlias

Expand Down Expand Up @@ -281,8 +280,8 @@ def check_options(self) -> None:
"may cause an unexpected behaviour with launch-per-plan structure")

@property
def time(self) -> str:
return str(int(time() * 1000))
def datetime(self) -> str:
return datetime.datetime.now(datetime.timezone.utc).isoformat()

@property
def headers(self) -> dict[str, str]:
Expand Down Expand Up @@ -396,13 +395,14 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
self.warn("SSL verification is disabled for all requests being made to ReportPortal "
f"instance ({self.data.url}).")

launch_time = self.time
launch_time = self.datetime

# Support for idle tests
executed = bool(self.step.plan.execute.results())
if executed:
# launch time should be the earliest start time of all plans
launch_time = min([r.start_time or self.time
# TODO: Does the 'min' work with datetime isoformat correctly?
launch_time = min([r.start_time or self.datetime
for r in self.step.plan.execute.results()])

# Create launch, suites (if "--suite_per_plan") and tests;
Expand Down Expand Up @@ -533,7 +533,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:

for result, test in self.step.plan.execute.results_for_tests(
self.step.plan.discover.tests()):
test_time = self.time
test_time = self.datetime
test_name = None
test_description = ''
test_link = None
Expand All @@ -544,7 +544,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
if result:
serial_number = result.serial_number
test_name = result.name
test_time = result.start_time or self.time
test_time = result.start_time or self.datetime
# for guests, save their primary address
if result.guest.primary_address:
item_attributes.append({
Expand Down Expand Up @@ -595,12 +595,14 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
"type": "step",
"testCaseId": test_id,
"startTime": test_time})

item_uuid = yaml_to_dict(response.text).get("id")
assert item_uuid is not None
self.verbose("uuid", item_uuid, "yellow", shift=1)
self.data.test_uuids[serial_number] = item_uuid
else:
item_uuid = self.data.test_uuids[serial_number]

# Support for idle tests
status = "SKIPPED"
if result:
Expand Down Expand Up @@ -636,7 +638,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
"level": "ERROR",
"time": result.end_time})

test_time = result.end_time or self.time
test_time = result.end_time or self.datetime

# Finish the test item
response = self.rp_api_put(
Expand All @@ -648,6 +650,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
"status": status,
"issue": {
"issueType": self.get_defect_type_locator(session, defect_type)}})

launch_time = test_time

if create_suite:
Expand Down

0 comments on commit fcb9d72

Please sign in to comment.