Esempio n. 1
0
    def run_tests(self, handle_coverage=True):
        """ runs all tests """
        sys.stdout.write("Finding files... ")
        files = self.find_import_files()
        if self.verbosity > 3:
            sys.stdout.write('%s ... done.\n' % (self.files_or_dirs))
        else:
            sys.stdout.write('done.\n')
        sys.stdout.write("Importing test modules ... ")

        if handle_coverage:
            coverage_files, coverage = StartCoverageSupport(self.configuration)

        file_and_modules_and_module_name = self.find_modules_from_files(files)
        sys.stdout.write("done.\n")

        all_tests = self.find_tests_from_modules(
            file_and_modules_and_module_name)
        if self.test_filter or self.tests:

            if self.test_filter:
                sys.stdout.write('Test Filter: %s\n' %
                                 ([p.pattern for p in self.test_filter], ))

            if self.tests:
                sys.stdout.write('Tests to run: %s\n' % (self.tests, ))

            all_tests = self.filter_tests(all_tests)

        test_suite = unittest.TestSuite(all_tests)
        import pydev_runfiles_xml_rpc
        pydev_runfiles_xml_rpc.notifyTestsCollected(
            test_suite.countTestCases())

        executed_in_parallel = False
        start_time = time.time()
        if self.jobs > 1:
            import pydev_runfiles_parallel

            #What may happen is that the number of jobs needed is lower than the number of jobs requested
            #(e.g.: 2 jobs were requested for running 1 test) -- in which case ExecuteTestsInParallel will
            #return False and won't run any tests.
            executed_in_parallel = pydev_runfiles_parallel.ExecuteTestsInParallel(
                all_tests, self.jobs, self.split_jobs, self.verbosity,
                coverage_files, self.configuration.coverage_include)

        if not executed_in_parallel:
            #If in coverage, we don't need to pass anything here (coverage is already enabled for this execution).
            runner = pydev_runfiles_unittest.PydevTextTestRunner(
                stream=sys.stdout, descriptions=1, verbosity=self.verbosity)
            sys.stdout.write('\n')
            runner.run(test_suite)

        if handle_coverage:
            coverage.stop()
            coverage.save()

        total_time = 'Finished in: %.2f secs.' % (time.time() - start_time, )
        pydev_runfiles_xml_rpc.notifyTestRunFinished(total_time)
        def run_tests():
            executed_in_parallel = False
            if self.jobs > 1:
                import pydev_runfiles_parallel

                #What may happen is that the number of jobs needed is lower than the number of jobs requested
                #(e.g.: 2 jobs were requested for running 1 test) -- in which case ExecuteTestsInParallel will
                #return False and won't run any tests.
                executed_in_parallel = pydev_runfiles_parallel.ExecuteTestsInParallel(
                    all_tests, self.jobs, self.split_jobs, self.verbosity,
                    coverage_files, self.configuration.coverage_include)

            if not executed_in_parallel:
                #If in coverage, we don't need to pass anything here (coverage is already enabled for this execution).
                runner = pydev_runfiles_unittest.PydevTextTestRunner(
                    stream=sys.stdout,
                    descriptions=1,
                    verbosity=self.verbosity)
                sys.stdout.write('\n')
                runner.run(test_suite)