9d16240c327a5803cb017d83165dd460fbb8f472,src/python/pants/backend/jvm/tasks/junit_run.py,JUnitRun,_get_failed_targets,#JUnitRun#Any#,275

Before Change


        self.context.log.warn("Unknown target for test %{0}".format(test))

      filename = get_test_filename(test)
      if os.path.exists(filename):
        try:
          xml = XmlParser.from_file(filename)
          str_failures = xml.get_attribute("testsuite", "failures")
          int_failures = int(str_failures)

          str_errors = xml.get_attribute("testsuite", "errors")
          int_errors = int(str_errors)

          if target and (int_failures or int_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, ValueError) as e:
          self.context.log.error("Error parsing test result file {0}: {1}".format(filename, e))
      else:
        // If the test file doesn"t exist, then it must have failed before running the tests, so we should
        // ensure this target is in failed_targets, but we don"t have details about which testclass//testname
        // failed. Instead we just use the "test" up to the first "$".
        test_split = test.split("$")
        failed_targets[target].add(test_split[0])

    return dict(failed_targets)

  def _run_tests(self, tests_to_targets):

After Change


    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)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 7

Instances


Project Name: pantsbuild/pants
Commit Name: 9d16240c327a5803cb017d83165dd460fbb8f472
Time: 2016-03-28
Author: cheister@gmail.com
File Name: src/python/pants/backend/jvm/tasks/junit_run.py
Class Name: JUnitRun
Method Name: _get_failed_targets


Project Name: danforthcenter/plantcv
Commit Name: a99de822ad4c2b57061192e1e78a7e49f7ebc1dc
Time: 2019-09-30
Author: haleyschuhl@gmail.com
File Name: plantcv/plantcv/apply_mask.py
Class Name:
Method Name: apply_mask


Project Name: soft-matter/trackpy
Commit Name: 83d1a46c72c12f8140d5232de59097d894d9d5f7
Time: 2013-01-22
Author: daniel.b.allan@gmail.com
File Name: mr/fitting.py
Class Name:
Method Name: NLS