Пример #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.
    """
    coverage.use_cache(0)
    for e in settings.COVERAGE_CODE_EXCLUDES:
        coverage.exclude(e)
    coverage.start()
    results = base_run_tests(test_labels, verbosity, interactive, extra_tests)
    coverage.stop()

    coverage_modules = []
    if test_labels:
        for label in test_labels:
            label = label.split('.')[0]
            app = get_app(label)
            coverage_modules.append(_get_app_package(app))
    else:
        for app in get_apps():
            coverage_modules.append(_get_app_package(app))

    coverage_modules.extend(settings.COVERAGE_ADDITIONAL_MODULES)

    packages, modules, excludes, errors = get_all_modules(
        coverage_modules, settings.COVERAGE_MODULE_EXCLUDES,
        settings.COVERAGE_PATH_EXCLUDES)

    outdir = settings.COVERAGE_REPORT_HTML_OUTPUT_DIR
    if outdir is None:
        coverage.report(modules.values(), show_missing=1)
        if excludes:
            print >>sys.stdout
            print >>sys.stdout, "The following packages or modules were excluded:",
            for e in excludes:
                print >>sys.stdout, e,
            print >>sys.stdout
        if errors:
            print >>sys.stdout
            print >>sys.stderr, "There were problems with the following packages or modules:",
            for e in errors:
                print >>sys.stderr, e,
            print >>sys.stdout
    else:
        outdir = os.path.abspath(outdir)
        if settings.COVERAGE_CUSTOM_REPORTS:
            html_report(outdir, modules, excludes, errors)
        else:
            coverage._the_coverage.html_report(modules.values(), outdir)
            coverage._the_coverage.xml_report(modules.values(), os.path.join(outdir,'coverage.xml') )
        print >>sys.stdout
        print >>sys.stdout, "HTML reports were output to '%s'" %outdir

    return results
Пример #2
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.
    """
    coverage.use_cache(0)
    for e in getattr(settings, 'COVERAGE_CODE_EXCLUDES', []):
        coverage.exclude(e)
    coverage.start()
    results = base_run_tests(test_labels, verbosity, interactive, extra_tests)
    coverage.stop()

    coverage_modules = []
    if test_labels:
        for label in test_labels:
            label = label.split('.')[0]
            app = get_app(label)
            coverage_modules.append(_get_app_package(app))
    else:
        for app in get_apps():
            coverage_modules.append(_get_app_package(app))

    coverage_modules.extend(
        getattr(settings, 'COVERAGE_ADDITIONAL_MODULES', []))

    packages, modules, excludes, errors = get_all_modules(
        coverage_modules, getattr(settings, 'COVERAGE_MODULE_EXCLUDES', []),
        getattr(settings, 'COVERAGE_PATH_EXCLUDES', []))

    coverage.report(modules.values(), show_missing=1)
    if excludes:
        print >> sys.stdout
        print >> sys.stdout, "The following packages or modules were excluded:",
        for e in excludes:
            print >> sys.stdout, e,
        print >> sys.stdout
    if errors:
        print >> sys.stdout
        print >> sys.stderr, "There were problems with the following packages or modules:",
        for e in errors:
            print >> sys.stderr, e,
        print >> sys.stdout

    outdir = getattr(settings, 'COVERAGE_REPORT_HTML_OUTPUT_DIR', 'test_html')
    outdir = os.path.abspath(outdir)
    html_report(outdir, modules, excludes, errors)
    print >> sys.stdout
    print >> sys.stdout, "HTML reports were output to '%s'" % outdir

    return results
Пример #3
0
    #####

    coverage_modules = []
    if test_labels:
        for label in test_labels:
            label = label.split('.')[0]
            app = get_app(label)
            coverage_modules.append(_get_app_package(app))
    else:
        for app in get_apps():
            coverage_modules.append(_get_app_package(app))

    coverage_modules.extend(default_settings.COVERAGE_ADDITIONAL_MODULES)

    packages, modules, excludes, errors = get_all_modules(
        coverage_modules, default_settings.COVERAGE_MODULE_EXCLUDES,
        default_settings.COVERAGE_PATH_EXCLUDES)

    outdir = default_settings.COVERAGE_REPORT_HTML_OUTPUT_DIR
    if outdir is None:
        coverage.report(modules.values(), show_missing=1)
        if excludes:
            print >>sys.stdout
            print >>sys.stdout, "The following packages or modules were excluded:",
            for e in excludes:
                print >>sys.stdout, e,
            print >>sys.stdout
        if errors:
            print >>sys.stdout
            print >>sys.stderr, "There were problems with the following packages or modules:",
            for e in errors:
Пример #4
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.
    """
    ##############################
    setup_funcs, teardown_funcs = get_test_enviroment_functions()
    # Prepare django for testing.
    setup_test_environment(setup_funcs)
    old_db_name = settings.DATABASE_NAME
    connection.creation.create_test_db(verbosity, autoclobber=not interactive)

    # Pretend it's a production environment.
    settings.DEBUG = False

    nose_argv = ['nosetests']
    if hasattr(settings, 'NOSE_ARGS'):
        nose_argv.extend(settings.NOSE_ARGS)

    # Everything after '--' is passed to nose.
    if '--' in sys.argv:
        hyphen_pos = sys.argv.index('--')
        nose_argv.extend(sys.argv[hyphen_pos + 1:])

    if verbosity >= 1:
        print ' '.join(nose_argv)

    ############################

    coverage.use_cache(0)
    for e in settings.COVERAGE_CODE_EXCLUDES:
        coverage.exclude(e)
    coverage.start()
    nose.run(argv=nose_argv)    
    #results = base_run_tests(test_labels, verbosity, interactive, extra_tests)
    coverage.stop()

    coverage_modules = []
    if test_labels:
        for label in test_labels:
            label = label.split('.')[0]
            app = get_app(label)
            coverage_modules.append(_get_app_package(app))
    else:
        for app in get_apps():
            coverage_modules.append(_get_app_package(app))

    coverage_modules.extend(settings.COVERAGE_ADDITIONAL_MODULES)

    packages, modules, excludes, errors = get_all_modules(
        coverage_modules, settings.COVERAGE_MODULE_EXCLUDES,
        settings.COVERAGE_PATH_EXCLUDES)

    outdir = settings.COVERAGE_REPORT_HTML_OUTPUT_DIR
    if outdir is None:
        coverage.report(modules.values(), show_missing=1)
        if excludes:
            print >>sys.stdout
            print >>sys.stdout, "The following packages or modules were excluded:",
            for e in excludes:
                print >>sys.stdout, e,
            print >>sys.stdout
        if errors:
            print >>sys.stdout
            print >>sys.stderr, "There were problems with the following packages or modules:",
            for e in errors:
                print >>sys.stderr, e,
            print >>sys.stdout
    else:
        outdir = os.path.abspath(outdir)
        if settings.COVERAGE_CUSTOM_REPORTS:
            html_report(outdir, modules, excludes, errors)
        else:
            coverage._the_coverage.html_report(modules.values(), outdir)
        print >>sys.stdout
        print >>sys.stdout, "HTML reports were output to '%s'" %outdir

    ###########################
    # Clean up django.
    connection.creation.destroy_test_db(old_db_name, verbosity)
    teardown_test_environment(teardown_funcs)
    ###########################

    return results