Skip to content

Commit

Permalink
Provide mapping between results and tests for easier reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
happz committed Sep 18, 2024
1 parent 97374ce commit de190d1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tmt/steps/execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,3 +1169,29 @@ def results(self) -> list["tmt.result.Result"]:
https://tmt.readthedocs.io/en/latest/spec/plans.html#execute
"""
return self._results

def results_for_tests(self, tests: list['tmt.base.Test']) \
-> list[tuple[Optional[Result], Optional['tmt.base.Test']]]:
"""
Collect results and corresponding tests.
:returns: a list of result and test pairs.
* if there is not test found for the result, e.g. when
results were loaded from storage but tests were not,
``None`` represents the missing test: ``(result, None)``.
* if there is no result for a test, e.g. when the test was
not executed, ``None`` represents the missing result:
``(None, test)``.
"""

known_serial_numbers = {test.serial_number: test for test in tests}
referenced_serial_numbers = {result.serial_number for result in self._results}

return [
(result, known_serial_numbers.get(result.serial_number))
for result in self._results
] + [
(None, test)
for test in tests
if test.serial_number in referenced_serial_numbers
]

0 comments on commit de190d1

Please sign in to comment.