Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguishing between JUnit final results and XUnit2 intermediate (rerun) results #144

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions junitparser/junitparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,12 @@ def text(self, value: str):
self._elem.text = value


class Skipped(Result):
class FinalResult(Result):
"""Base class for final test result (in contrast to XUnit2 RerunResult)."""

_tag = None

class Skipped(FinalResult):
"""Test result when the case is skipped."""

_tag = "skipped"
Expand All @@ -250,7 +255,7 @@ def __eq__(self, other):
return super().__eq__(other)


class Failure(Result):
class Failure(FinalResult):
"""Test result when the case failed."""

_tag = "failure"
Expand All @@ -259,7 +264,7 @@ def __eq__(self, other):
return super().__eq__(other)


class Error(Result):
class Error(FinalResult):
"""Test result when the case has errors during execution."""

_tag = "error"
Expand All @@ -268,7 +273,7 @@ def __eq__(self, other):
return super().__eq__(other)


POSSIBLE_RESULTS = {Failure, Error, Skipped}
FINAL_RESULTS = {Failure, Error, Skipped}


class System(Element):
Expand Down Expand Up @@ -329,7 +334,7 @@ def __hash__(self):
return super().__hash__()

def __iter__(self):
all_types = set.union(POSSIBLE_RESULTS, {SystemOut}, {SystemErr})
all_types = set.union(FINAL_RESULTS, {SystemOut}, {SystemErr})
for elem in self._elem.iter():
for entry_type in all_types:
if elem.tag == entry_type._tag:
Expand All @@ -353,27 +358,30 @@ def is_skipped(self):
return False

@property
def result(self):
def result(self) -> List[FinalResult]:
"""A list of :class:`Failure`, :class:`Skipped`, or :class:`Error` objects."""
results = []
for entry in self:
if isinstance(entry, tuple(POSSIBLE_RESULTS)):
if isinstance(entry, FinalResult):
results.append(entry)

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 any(isinstance(entry, r) for r in POSSIBLE_RESULTS):
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 any(isinstance(entry, r) for r in POSSIBLE_RESULTS):
self.append(entry)
self.append(entry)

@property
def system_out(self):
Expand Down
16 changes: 9 additions & 7 deletions junitparser/xunit2.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ class StackTrace(junitparser.System):
_tag = "stackTrace"


class RerunType(junitparser.Result):
_tag = "rerunType"
class RerunResult(junitparser.Result):
"""Base class for intermediate / rerun test result (in contrast to JUnit FinalResult)."""

_tag = None

@property
def stack_trace(self):
Expand Down Expand Up @@ -157,19 +159,19 @@ def system_err(self, value: str):
self.append(err)


class RerunFailure(RerunType):
class RerunFailure(RerunResult):
_tag = "rerunFailure"


class RerunError(RerunType):
class RerunError(RerunResult):
_tag = "rerunError"


class FlakyFailure(RerunType):
class FlakyFailure(RerunResult):
_tag = "flakyFailure"


class FlakyError(RerunType):
class FlakyError(RerunResult):
_tag = "flakyError"


Expand Down Expand Up @@ -199,6 +201,6 @@ def flaky_errors(self):
"""<flakyError>"""
return self._rerun_results(FlakyError)

def add_rerun_result(self, result: RerunType):
def add_rerun_result(self, result: RerunResult):
"""Append a rerun result to the testcase. A testcase can have multiple rerun results."""
self.append(result)
Loading