diff --git a/junitparser/junitparser.py b/junitparser/junitparser.py index f25c202..6790feb 100644 --- a/junitparser/junitparser.py +++ b/junitparser/junitparser.py @@ -8,10 +8,9 @@ See the documentation for other supported schemas. """ - import itertools from copy import deepcopy -from typing import List +from typing import List, Union try: from lxml import etree @@ -364,14 +363,17 @@ def result(self): return results @result.setter - def result(self, value: Result): + def result(self, value: Union[Result, List[Result]]): # First remove all existing results for entry in self.result: if any(isinstance(entry, r) for r in POSSIBLE_RESULTS): self.remove(entry) - for entry in value: - if any(isinstance(entry, r) for r in POSSIBLE_RESULTS): - self.append(entry) + if isinstance(value, Result): + self.append(value) + elif isinstance(value, list): + for entry in value: + if any(isinstance(entry, r) for r in POSSIBLE_RESULTS): + self.append(entry) @property def system_out(self): diff --git a/tests/test_general.py b/tests/test_general.py index 7f96ebb..6205a6e 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -578,7 +578,8 @@ def test_case_output(self): def test_update_results(self): case = TestCase() - case.result = [Skipped()] + case.result = Skipped() + assert len(case.result) == 1 case.result = [Failure(), Skipped()] assert len(case.result) == 2