Skip to content

Commit

Permalink
Recursively check for errors/failures in produced JUnit result XMLs
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Morales <ngmorales97@gmail.com>
  • Loading branch information
ngmor committed May 10, 2023
1 parent 154f198 commit a4daa37
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 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,21 @@ 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
if (int(node.attrib.get('errors', 0))) or (int(node.attrib.get('failures', 0))):
return True

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

0 comments on commit a4daa37

Please sign in to comment.