From 8af5e1f8e72b852cc1c7823eb796625807065db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Prchl=C3=ADk?= Date: Wed, 18 Sep 2024 11:08:28 +0200 Subject: [PATCH] Provide mapping between results and tests for easier reporting --- tmt/steps/execute/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tmt/steps/execute/__init__.py b/tmt/steps/execute/__init__.py index f1da4e7d52..63d91bad74 100644 --- a/tmt/steps/execute/__init__.py +++ b/tmt/steps/execute/__init__.py @@ -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 not in referenced_serial_numbers + ]