Exemplo n.º 1
0
def run_tests(test_labels, verbosity=1, interactive=True,
        extra_tests=[]):
    """
    Test runner which displays a code coverage report at the end of the
    run.
    """
    django_test_runner = get_runner(settings)
    coverage.use_cache(0)
    coverage.start()
    
    results = django_test_runner(test_labels, verbosity, interactive, 
        extra_tests)
    coverage.stop()

    coverage_modules = []
    if test_labels:
        for label in test_labels:
            # Don't report coverage if you're only running a single
            # test case.
            if '.' not in label:
                app = get_app(label)
                coverage_modules.extend(get_all_coverage_modules(app))
    else:
        for app in get_apps():
            coverage_modules.extend(get_all_coverage_modules(app))

    if coverage_modules:
        coverage.report(coverage_modules, show_missing=1)

    return results
Exemplo n.º 2
0
    def handle(self, *test_labels, **options):

        verbosity = int(options.get('verbosity', 1))
        interactive = options.get('interactive', True)
        
        # it's quite possible someone, lets say South, might have stolen
        # the syncdb command from django. For testing purposes we should
        # probably put it back. Migrations don't really make sense
        # for tests. Actually the South test runner does this too.
        management.get_commands()
        management._commands['syncdb'] = 'django.core'

        if options.get('coverage'):
            test_runner_name = 'django_kwalitee.testrunners.codecoverage.run_tests'
        else:
            test_runner_name = settings.TEST_RUNNER
        
        # hack to run subset of full test suite
        # just use test_labels to load up non-excluded apps
        if options.get('local') and not test_labels:
            local_apps = []
            for app in get_apps():
                app_label = app.__name__.split('.')[-2]
                if not app_label in settings.KWALITEE_LOCAL_EXCLUDES:
                    local_apps.append(app_label)
            test_labels = tuple(local_apps)
        
        test_runner = get_runner(test_runner_name)

        failures = test_runner(test_labels, verbosity=verbosity, 
            interactive=interactive)
        if failures:
            sys.exit(failures)