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

Recursively check for errors/failures in produced JUnit result XMLs #446

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 31 additions & 4 deletions ament_cmake_test/ament_cmake_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,7 @@ def log(msg, **kwargs):
rc = 1
else:
# set error code when result file contains errors or failures
root = tree.getroot()
num_errors = int(root.attrib.get('errors', 0))
num_failures = int(root.attrib.get('failures', 0))
if num_errors or num_failures:
if _check_for_failure(tree):
rc = 1

# ensure that a result file exists at the end
Expand All @@ -318,6 +315,36 @@ def log(msg, **kwargs):

return rc

def _check_for_failure(tree):
# Check tree for failures in nodes
root = tree.getroot()
return _check_for_failure_recursive(root)

def _check_for_failure_recursive(node):
# Recursively check node and subnodes for test error or failure

# First check if this node has nonzero error or failure attributes
# Return True (signifying a failure) if that is the case
if (int(node.attrib.get('errors', 0))) or (int(node.attrib.get('failures', 0))):
return True

# Next check if the node is a "testsuite" tag.
if node.tag == 'testsuite':
# Check if the tag has error and/or failure attributes
if ((node.attrib.get('errors') is not None)
or (node.attrib.get('failures') is not None)):
# If so, we already know from above check that these attributes
# must have a zero value. Don't descend further into a testsuite
# tag that has error and/or failure attributes with a zero value.
# Return False indicating no failure in this branch.
return False

# Otherwise, recursively check for failures inside this node
for child in node:
if _check_for_failure_recursive(child):
return True

return False

def _generate_result(result_file, *, failure_message=None, skip=False,
error_message=None, test_time=0):
Expand Down