Skip to content

Commit

Permalink
Import the tmt subresults into the ReportPortal
Browse files Browse the repository at this point in the history
  • Loading branch information
seberm committed Nov 12, 2024
1 parent 3ed197b commit 3b7b5a4
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions tmt/steps/report/reportportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
@tmt.steps.provides_method("reportportal")
class ReportReportPortal(tmt.steps.report.ReportPlugin[ReportReportPortalData]):
"""
Report test results to a ReportPortal instance via API.
Report test results and their subresults to a ReportPortal instance via API.
For communication with Report Portal API is necessary to provide
following options:
Expand Down Expand Up @@ -608,6 +608,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
status = "SKIPPED"
if result:
# For each log
# TODO: Try to save logs for subresults?
for index, log_path in enumerate(result.log):
try:
log = self.step.plan.execute.read(log_path)
Expand Down Expand Up @@ -641,7 +642,45 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:

test_time = result.end_time or self.datetime

# Finish the test item
# Also create (and *finish*) the child test item for every tmt subresult and
# map it under parent test item
for subresult in result.subresult:
# Create a child item
response = self.rp_api_post(
session=session,
path=f"item/{item_uuid}",
json={
"name": subresult.name,
# TODO: Decide which attributes we want to set for subresults
# "description": test_description,
# "attributes": item_attributes,
# "parameters": env_vars,
# "codeRef": test_link,
"launchUuid": launch_uuid,
"type": "step",
# "testCaseId": test_id,
"startTime": subresult.start_time or self.datetime})

child_item_uuid = yaml_to_dict(response.text).get("id")
assert child_item_uuid is not None

# Finish the child item
response = self.rp_api_put(
session=session,
path=f"item/{item_uuid}",
json={
"launchUuid": launch_uuid,
"status": self.TMT_TO_RP_RESULT_STATUS[subresult.result],
# TODO: Workaround: The problem is, that the `start-time` for
# subresults is not set by `tmt-report-result` and the `end-time`
# **is** and it's **lower** than autogenerated `start-time` set by
# `self.datetime`.
# "endTime": subresult.end_time,
"endTime": self.datetime})

self.verbose("child uuid", child_item_uuid, "yellow", shift=2)

# Finish the parent test item
response = self.rp_api_put(
session=session,
path=f"item/{item_uuid}",
Expand Down

0 comments on commit 3b7b5a4

Please sign in to comment.