Ticket #8363: exclude_tests.diff

File exclude_tests.diff, 2.9 KB (added by Ramiro Morales, 16 years ago)
  • django/test/simple.py

    diff -r 93cbbb7609e6 django/test/simple.py
    a b  
    9999    else: # label is app.TestClass.test_method
    100100        return TestClass(parts[2])
    101101
    102 def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
     102def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], all_excluded=False):
    103103    """
    104104    Run the unit tests for all the test labels in the provided list.
    105105    Labels must be of the form:
     
    122122   
    123123    settings.DEBUG = False   
    124124    suite = unittest.TestSuite()
    125    
    126     if test_labels:
     125
     126    if all_excluded:
     127        tmp = [model[1:] for model in test_labels]
     128        test_labels = set(tmp)
     129
     130    if test_labels and not all_excluded:
    127131        for label in test_labels:
    128132            if '.' in label:
    129133                suite.addTest(build_test(label))
    130134            else:
    131135                app = get_app(label)
    132136                suite.addTest(build_suite(app))
     137    elif all_excluded:
     138        for app in get_apps():
     139            if app.__name__.split('.')[-2] in test_labels:
     140                print 'skipping %s' % app.__name__
     141                continue
     142            suite.addTest(build_suite(app))
    133143    else:
    134144        for app in get_apps():
    135145            suite.addTest(build_suite(app))
  • tests/runtests.py

    diff -r 93cbbb7609e6 tests/runtests.py
    a b  
    117117    from django.db.models.loading import get_apps, load_app
    118118    get_apps()
    119119
     120    if not test_labels:
     121        all_excluded = False
     122    else:
     123        all_excluded = True
     124        for tl in test_labels:
     125            if tl[0] != '-':
     126                all_excluded = False
     127
    120128    # Load all the test model apps.
     129    test_label_set = set([label.split('.')[0] for label in test_labels])
    121130    for model_dir, model_name in get_test_models():
    122131        model_label = '.'.join([model_dir, model_name])
    123132        try:
    124133            # if the model was named on the command line, or
    125134            # no models were named (i.e., run all), import
    126135            # this model and add it to the list to test.
    127             if not test_labels or model_name in set([label.split('.')[0] for label in test_labels]):
     136            if not test_labels or all_excluded or model_name in test_label_set:
    128137                if verbosity >= 1:
    129138                    print "Importing model %s" % model_name
    130139                mod = load_app(model_label)
     
    150159   
    151160    # Run the test suite, including the extra validation tests.
    152161    from django.test.simple import run_tests
    153     failures = run_tests(test_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests)
     162    failures = run_tests(test_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests, all_excluded=all_excluded)
    154163    if failures:
    155164        sys.exit(failures)
    156165
Back to Top