From 3c0db45a3b70d4b045a02e08fd1a862e4f3aefa2 Mon Sep 17 00:00:00 2001 From: Wang Weiwei Date: Sat, 31 Aug 2024 21:01:06 -0700 Subject: [PATCH] fix #133 typing (#135) Co-authored-by: Joel Wang --- junitparser/junitparser.py | 14 ++++++++------ tests/test_general.py | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) 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