Example #1
0
    def run_serialized(self,
                       master_suite,
                       test_runner,
                       result_type=None,
                       results_path=None):

        exit_code = 0
        unittest.installHandler()
        start_time = time.time()
        result = test_runner.run(master_suite)
        total_execution_time = time.time() - start_time

        if result_type is not None:
            result_parser = SummarizeResults(vars(result), master_suite,
                                             total_execution_time)
            all_results = result_parser.gather_results()
            reporter = Reporter(result_parser=result_parser,
                                all_results=all_results)
            reporter.generate_report(result_type=result_type,
                                     path=results_path)

        self._log_results(result)
        if not result.wasSuccessful():
            exit_code = 1

        return exit_code
Example #2
0
    def compile_results(self, run_time, datagen_time, results):
        """Summarizes results and writes results to file if --result used"""
        all_results = []
        result_dict = {"tests": 0, "errors": 0, "failures": 0, "skipped": 0}
        for dic in results:
            result = dic["result"]
            tests = [
                suite for suite in self.suites
                if suite.cafe_uuid == dic["cafe_uuid"]
            ][0]
            result_parser = SummarizeResults(result_dict=vars(result),
                                             tests=tests,
                                             execution_time=run_time,
                                             datagen_time=datagen_time)
            all_results += result_parser.gather_results()
            summary = result_parser.summary_result()
            for key in result_dict:
                result_dict[key] += summary[key]

            if result.stream.buf.strip():
                # this line can be replace to add an extensible stdout/err log
                sys.stderr.write("{0}\n\n".format(result.stream.buf.strip()))

        if self.cl_args.result is not None:
            reporter = Reporter(result_parser, all_results)
            reporter.generate_report(self.cl_args.result,
                                     self.cl_args.result_directory)
        return self.print_results(run_time=run_time,
                                  datagen_time=datagen_time,
                                  **result_dict)
    def setUp(self):
        """ Creates a SummarizeResults parser with fake tests and initializes
        the reporter. Also creates a directory for the created reports.
        """
        test_suite = unittest.suite.TestSuite()
        test_suite.addTest(FakeTests('test_report_pass'))
        test_suite.addTest(FakeTests('test_report_fail'))
        test_suite.addTest(FakeTests('test_report_skip'))
        test_suite.addTest(FakeTests('test_report_error'))

        self.failure_trace = 'Traceback: ' + str(uuid4())
        self.skip_msg = str(uuid4())
        self.error_trace = 'Traceback: ' + str(uuid4())
        result = {
            'testsRun': 4,
            'errors': [(FakeTests('test_report_error'), self.error_trace)],
            'skipped': [(FakeTests('test_report_skip'), self.skip_msg)],
            'failures': [(FakeTests('test_report_fail'), self.failure_trace)]}

        self.result_parser = SummarizeResults(
            master_testsuite=test_suite, result_dict=result,
            execution_time=1.23)
        self.all_results = self.result_parser.gather_results()
        self.reporter = Reporter(
            result_parser=self.result_parser, all_results=self.all_results,)

        self.results_dir = os.getcwd() + os.path.sep + 'test-reporting-results'
        if not os.path.exists(self.results_dir):
            os.makedirs(self.results_dir)
Example #4
0
    def run_parallel(self,
                     test_suites,
                     test_runner,
                     result_type=None,
                     results_path=None):

        exit_code = 0
        proc = None
        unittest.installHandler()
        processes = []
        manager = Manager()
        results = manager.dict()
        manager.dict()
        start = time.time()

        test_mapping = {}
        for test_suite in test_suites:
            # Give each test suite an uuid so it can be
            # matched to the correct test result
            test_id = str(uuid.uuid4())
            test_mapping[test_id] = test_suite

            proc = Process(target=self.execute_test,
                           args=(test_runner, test_id, test_suite, results))
            processes.append(proc)
            proc.start()

        for proc in processes:
            proc.join()

        finish = time.time()

        errors, failures, _ = self.dump_results(start, finish, results)

        if result_type is not None:
            all_results = []
            for test_id, result in list(results.items()):
                tests = test_mapping[test_id]
                result_parser = SummarizeResults(vars(result), tests,
                                                 (finish - start))
                all_results += result_parser.gather_results()

            reporter = Reporter(result_parser=result_parser,
                                all_results=all_results)
            reporter.generate_report(result_type=result_type,
                                     path=results_path)

        if failures or errors:
            exit_code = 1

        return exit_code