Skip to content

Add a "collection of results" class for collection-wide actions - #5027

Open
happz wants to merge 2 commits into
results-drop-showfrom
results-collection
Open

Add a "collection of results" class for collection-wide actions#5027
happz wants to merge 2 commits into
results-drop-showfrom
results-collection

Conversation

@happz

@happz happz commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Sevral methods are tied to the Result class, but apply to a list[Result]. Instead, let's have a class representing a collection of results, and let that one own the collection-level operations like summary.

Pull Request Checklist

  • implement the feature

Sevral methods are tied to the `Result` class, but apply to a
`list[Result]`. Instead, let's have a class representing a collection of
results, and let that one own the collection-level operations like
`summary`.
@happz happz added this to planning Jul 1, 2026
@happz happz added code | no functional change "No Functional Change" intended. Patch should not change tmt's behavior in any way. area | results Related to how tmt stores and shares results ci | full test Pull request is ready for the full test execution labels Jul 1, 2026
@github-project-automation github-project-automation Bot moved this to backlog in planning Jul 1, 2026
@happz happz moved this from backlog to implement in planning Jul 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Results collection class inheriting from list to manage test results, refactoring various steps and runs to use it instead of standard lists. Feedback suggests overriding __getitem__, __add__, and copy in Results to prevent type degradation back to a standard list during operations, using .copy() directly instead of slicing, and simplifying redundant fully qualified type annotations.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tmt/result.py
Comment on lines +531 to +539
class Results(list[ResultT]):
"""
A collection of results.

Effectively a fancy list of results, with a few helper methods for
the collection as a whole.
"""

def total(self) -> dict[ResultOutcome, int]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Override __getitem__, __add__, and copy in the Results class to preserve the custom Results collection type during slicing, concatenation, and copying operations. Slicing or copying a standard list subclass otherwise degrades the type back to a standard list, which can cause runtime errors if collection-specific methods (like .summary()) are called on the resulting object.

Suggested change
class Results(list[ResultT]):
"""
A collection of results.
Effectively a fancy list of results, with a few helper methods for
the collection as a whole.
"""
def total(self) -> dict[ResultOutcome, int]:
class Results(list[ResultT]):
"""
A collection of results.
Effectively a fancy list of results, with a few helper methods for
the collection as a whole.
"""
def __getitem__(self, item: Any) -> Any:
if isinstance(item, slice):
return Results(super().__getitem__(item))
return super().__getitem__(item)
def __add__(self, other: list[Any]) -> 'Results[ResultT]':
return Results(super().__add__(other))
def copy(self) -> 'Results[ResultT]':
return Results(super().copy())
def total(self) -> dict[ResultOutcome, int]:

assert self.parent is not None # narrow type
assert isinstance(self.parent, Execute) # narrow type
self.parent._old_results = self.parent._results[:]
self.parent._old_results = Results(self.parent._results[:])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the .copy() method directly on the Results collection instead of slicing with [:] and wrapping it back in Results(...).

Suggested change
self.parent._old_results = Results(self.parent._results[:])
self.parent._old_results = self.parent._results.copy()

Comment thread tmt/steps/__init__.py
result_class: type[ResultT],
allow_missing: bool = False,
) -> list[ResultT]:
) -> tmt.result.Results[ResultT]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the directly imported Results class instead of the redundant tmt.result.Results prefix.

Suggested change
) -> tmt.result.Results[ResultT]:
) -> Results[ResultT]:

self._assert_required_tests_executed()

def results(self) -> list["tmt.result.Result"]:
def results(self) -> 'tmt.result.Results[tmt.result.Result]':

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use 'Results[Result]' instead of 'tmt.result.Results[tmt.result.Result]' since both classes are already imported directly in this file.

Suggested change
def results(self) -> 'tmt.result.Results[tmt.result.Result]':
def results(self) -> 'Results[Result]':

@happz happz moved this from implement to review in planning Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area | results Related to how tmt stores and shares results ci | full test Pull request is ready for the full test execution code | no functional change "No Functional Change" intended. Patch should not change tmt's behavior in any way.

Projects

Status: review

Development

Successfully merging this pull request may close these issues.

1 participant