def parse_failed_targets(test_registry, junit_xml_dir, error_handler):
 failed_targets = defaultdict(set)
 for name in os.listdir(junit_xml_dir):
  if _JUNIT_XML_MATCHER.match(name):
   try:
    path = os.path.join(junit_xml_dir, name)
    xml = XmlParser.from_file(path)
    failures = int(xml.get_attribute(u'testsuite', u'failures'))
    errors = int(xml.get_attribute(u'testsuite', u'errors'))
    if (failures or errors):
     for testcase in xml.parsed.getElementsByTagName(u'testcase'):
      test_failed = testcase.getElementsByTagName(u'failure')
      test_errored = testcase.getElementsByTagName(u'error')
      if (test_failed or test_errored):
       test = Test(classname=testcase.getAttribute(u'classname'), methodname=testcase.getAttribute(u'name'))
       target = test_registry.get_owning_target(test)
       failed_targets[target].add(test)
   except (XmlParser.XmlError, ValueError) as e:
    error_handler(ParseError(path, e))
 return dict(failed_targets)

def parse_failed_targets ( test_registry , junit_xml_dir , error_handler ) : failed_targets = defaultdict ( set ) for name in os . listdir ( junit_xml_dir ) : if _JUNIT_XML_MATCHER . match ( name ) : try : path = os . path . join ( junit_xml_dir , name ) xml = XmlParser . from_file ( path ) failures = int ( xml . get_attribute ( u'testsuite' , u'failures' ) ) errors = int ( xml . get_attribute ( u'testsuite' , u'errors' ) ) if ( failures or errors ) : for testcase in xml . parsed . getElementsByTagName ( u'testcase' ) : test_failed = testcase . getElementsByTagName ( u'failure' ) test_errored = testcase . getElementsByTagName ( u'error' ) if ( test_failed or test_errored ) : test = Test ( classname = testcase . getAttribute ( u'classname' ) , methodname = testcase . getAttribute ( u'name' ) ) target = test_registry . get_owning_target ( test ) failed_targets [ target ] . add ( test ) except ( XmlParser . XmlError , ValueError ) as e : error_handler ( ParseError ( path , e ) ) return dict ( failed_targets )
parses junit xml reports and maps targets to the set of individual tests that failed .