示例#1
0
    def load_test_results(self):
        results = []
        if self.build.plan.junit_path:
            for filename in iglob(self.build.plan.junit_path):
                results.extend(self.load_junit(filename))
            if not results:
                self.logger.warning('No results found at JUnit path {}'.format(
                    self.build.plan.junit_path
                ))
        try:
            results_filename = 'test_results.json'
            with open(results_filename, 'r') as f:
                results.extend(json.load(f))
            for result in results:
                result['SourceFile'] = results_filename
        except IOError as e:
            try:
                results_filename = 'test_results.xml'
                results.extend(self.load_junit(results_filename))
            except IOError as e:
                pass
        if not results:
            return
        import_test_results(self, results)

        self.tests_total = self.test_results.count()
        self.tests_pass = self.test_results.filter(outcome='Pass').count()
        self.tests_fail = self.test_results.filter(
            outcome__in=['Fail', 'CompileFail']).count()
        self.save()
示例#2
0
    def load_test_results(self):
        has_results = False

        root_dir_robot_path = f"{self.root_dir}/output.xml"
        # Load robotframework's output.xml if found
        if os.path.isfile("output.xml"):
            has_results = True
            import_robot_test_results(self, "output.xml")

        elif os.path.isfile(root_dir_robot_path):
            # FIXME: Not sure why robot stopped writing into the cwd
            # (build temp dir) but this should handle it so long as
            # only one build runs at a time
            has_results = True
            try:
                import_robot_test_results(self, root_dir_robot_path)
            finally:
                os.remove(root_dir_robot_path)

        # Load JUnit
        results = []
        if self.build.plan.junit_path:
            for filename in iglob(self.build.plan.junit_path):
                results.extend(self.load_junit(filename))
            if not results:
                self.logger.warning(
                    f"No results found at JUnit path {self.build.plan.junit_path}"
                )
        if results:
            has_results = True
            import_test_results(self, results, "JUnit")

        # Load from test_results.json
        results = []
        try:
            results_filename = "test_results.json"
            with open(results_filename, "r") as f:
                results.extend(json.load(f))
            for result in results:
                result["SourceFile"] = results_filename
        except IOError:
            try:
                results_filename = "test_results.xml"
                results.extend(self.load_junit(results_filename))
            except IOError:
                pass

        if results:
            has_results = True
            import_test_results(self, results, "Apex")

        if has_results:
            self.tests_total = self.test_results.count()
            self.tests_pass = self.test_results.filter(outcome="Pass").count()
            self.tests_fail = self.test_results.filter(
                outcome__in=["Fail", "CompileFail"]
            ).count()
            self.save()
示例#3
0
    def load_test_results(self):
        has_results = False

        root_dir_robot_path = '{}/output.xml'.format(
            self.root_dir,
        )
        # Load robotframework's output.xml if found
        if os.path.isfile('output.xml'):
            has_results = True
            import_robot_test_results(self, 'output.xml')

        elif os.path.isfile(root_dir_robot_path):
            # FIXME: Not sure why robot stopped writing into the cwd
            # (build temp dir) but this should handle it so long as
            # only one build runs at a time
            has_results = True
            import_robot_test_results(self, root_dir_robot_path)
            os.remove(root_dir_robot_path)

        # Load JUnit
        results = []
        if self.build.plan.junit_path:
            for filename in iglob(self.build.plan.junit_path):
                results.extend(self.load_junit(filename))
            if not results:
                self.logger.warning('No results found at JUnit path {}'.format(
                    self.build.plan.junit_path
                ))
        if results:
            has_results = True
            import_test_results(self, results, 'JUnit')

        # Load from test_results.json
        results = []
        try:
            results_filename = 'test_results.json'
            with open(results_filename, 'r') as f:
                results.extend(json.load(f))
            for result in results:
                result['SourceFile'] = results_filename
        except IOError as e:
            try:
                results_filename = 'test_results.xml'
                results.extend(self.load_junit(results_filename))
            except IOError as e:
                pass

        if results:
            has_results = True
            import_test_results(self, results, 'Apex')

        if has_results:
            self.tests_total = self.test_results.count()
            self.tests_pass = self.test_results.filter(outcome='Pass').count()
            self.tests_fail = self.test_results.filter(
                outcome__in=['Fail', 'CompileFail']).count()
            self.save()
示例#4
0
    def test_import_test_results(self, data):
        num_test_classes = TestClass.objects.all().count()
        num_test_methods = TestMethod.objects.all().count()
        num_test_results = TestResult.objects.all().count()

        with open("metaci/testresults/tests/junit_output.xml", "r") as f:
            results = data["buildflow"].load_junit(f)
        import_test_results(data["buildflow"], results, "Apex")

        assert TestClass.objects.all().count() == num_test_classes + 1
        assert TestMethod.objects.all().count() == num_test_methods + 2
        assert TestResult.objects.all().count() == num_test_results + 2

        test_result = TestResult.objects.get(method__name="test_method1")
        assert test_result.duration == 5.99
        assert test_result.outcome == "Pass"