Skip to content

Commit

Permalink
Simplify type checking in TestCase.result, enforce input types
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Dec 20, 2024
1 parent 61dfc24 commit 13f1182
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions junitparser/junitparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def is_skipped(self):
return False

@property
def result(self) -> list[FinalResult]:
def result(self) -> List[FinalResult]:
"""A list of :class:`Failure`, :class:`Skipped`, or :class:`Error` objects."""
results = []
for entry in self:
Expand All @@ -368,17 +368,20 @@ def result(self) -> list[FinalResult]:
return results

@result.setter
def result(self, value: Union[Result, List[Result]]):
def result(self, value: Union[FinalResult, List[FinalResult]]):
# Check typing
if not (isinstance(value, FinalResult) or
isinstance(value, list) and all(isinstance(item, FinalResult) for item in value)):
raise ValueError("Value must be either FinalResult or list of FinalResult")

# First remove all existing results
for entry in self.result:
if isinstance(entry, FinalResult):
self.remove(entry)
if isinstance(value, Result):
self.remove(entry)
if isinstance(value, FinalResult):
self.append(value)
elif isinstance(value, list):
else:
for entry in value:
if isinstance(entry, FinalResult):
self.append(entry)
self.append(entry)

@property
def system_out(self):
Expand Down

0 comments on commit 13f1182

Please sign in to comment.