def _get_failed_targets(self, tests_and_targets):
    """Return a mapping of target -> set of individual test cases that failed.

    Targets with no failed tests are omitted.

    Analyzes JUnit XML files to figure out which test had failed.

    The individual test cases are formatted strings of the form org.foo.bar.classname#methodName.

    :tests_and_targets: {test: target} mapping.
    """

    def get_test_filename(test_class_name):
      return os.path.join(self.workdir, 'TEST-{0}.xml'.format(test_class_name.replace('$', '-')))

    xml_filenames_to_targets = defaultdict()
    for test, target in tests_and_targets.items():
      if target is None:
        self.context.log.warn('Unknown target for test %{0}'.format(test))

      # Look for a TEST-*.xml file that matches the classname or a containing classname
      test_class_name = test
      for _part in test.split('$'):
        filename = get_test_filename(test_class_name)
        if os.path.exists(filename):
          xml_filenames_to_targets[filename] = target
          break
        else:
          test_class_name = test_class_name.rsplit('$', 1)[0]

    failed_targets = defaultdict(set)
    for xml_filename, target in xml_filenames_to_targets.items():
      try:
        xml = XmlParser.from_file(xml_filename)
        failures = int(xml.get_attribute('testsuite', 'failures'))
        errors = int(xml.get_attribute('testsuite', 'errors'))

        if target and (failures or errors):
          for testcase in xml.parsed.getElementsByTagName('testcase'):
            test_failed = testcase.getElementsByTagName('failure')
            test_errored = testcase.getElementsByTagName('error')
            if test_failed or test_errored:
              failed_targets[target].add('{testclass}#{testname}'.format(
                  testclass=testcase.getAttribute('classname'),
                  testname=testcase.getAttribute('name'),
              ))
      except (XmlParser.XmlError, __HOLE__) as e:
        self.context.log.error('Error parsing test result file {0}: {1}'.format(xml_filename, e))

    return dict(failed_targets)
dataset/ETHPy150Open pantsbuild/pants/src/python/pants/backend/jvm/tasks/junit_run.py/JUnitRun._get_failed_targets