Ticket #8363: 8363-r12262.diff

File 8363-r12262.diff, 4.9 KB (added by Ramiro Morales, 15 years ago)

Patch updated to r12262

  • django/test/simple.py

    diff -r 35931243adaa django/test/simple.py
    a b  
    208208        setup_test_environment()
    209209        settings.DEBUG = False
    210210
    211     def build_suite(self, test_labels, extra_tests=None):
     211    def build_suite(self, test_labels, extra_tests=None, exclude_labels=None):
    212212        suite = unittest.TestSuite()
    213213
     214        if exclude_labels is None:
     215            exclude_labels = []
     216
    214217        if test_labels:
    215218            for label in test_labels:
     219                if label in exclude_labels:
     220                    if self.verbosity >= 1:
     221                        print 'Skipping test %s' % label
     222                    continue
    216223                if '.' in label:
    217224                    suite.addTest(build_test(label))
    218225                else:
     
    250257    def suite_result(self, result):
    251258        return len(result.failures) + len(result.errors)
    252259
    253     def run_tests(self, test_labels, extra_tests=None):
     260    def run_tests(self, test_labels, extra_tests=None, exclude_labels=None):
    254261        """
    255262        Run the unit tests for all the test labels in the provided list.
    256263        Labels must be of the form:
     
    267274        A list of 'extra' tests may also be provided; these tests
    268275        will be added to the test suite.
    269276
     277        It's also possible to specify a list of labels to exclude from the
     278        test suite by using the exclude_labels parameter.
     279
    270280        Returns the number of tests that failed.
    271281        """
    272282        self.setup_test_environment()
    273283
    274         suite = self.build_suite(test_labels, extra_tests)
     284        suite = self.build_suite(test_labels, extra_tests, exclude_labels)
    275285
    276286        old_names = self.setup_databases()
    277287
  • tests/runtests.py

    diff -r 35931243adaa tests/runtests.py
    a b  
    8686        self.assert_(not unexpected, "Unexpected Errors: " + '\n'.join(unexpected))
    8787        self.assert_(not missing, "Missing Errors: " + '\n'.join(missing))
    8888
    89 def django_tests(verbosity, interactive, failfast, test_labels):
     89def django_tests(verbosity, interactive, failfast, test_labels, exclude_labels=None):
    9090    from django.conf import settings
    9191
     92    if exclude_labels is None:
     93        exclude_labels = []
     94
    9295    old_installed_apps = settings.INSTALLED_APPS
    9396    old_root_urlconf = getattr(settings, "ROOT_URLCONF", "")
    9497    old_template_dirs = settings.TEMPLATE_DIRS
     
    123126    get_apps()
    124127
    125128    # Load all the test model apps.
     129    test_labels_set = set([label.split('.')[0] for label in test_labels if label not in exclude_labels])
    126130    for model_dir, model_name in get_test_models():
    127131        model_label = '.'.join([model_dir, model_name])
    128132        try:
    129133            # if the model was named on the command line, or
    130134            # no models were named (i.e., run all), import
    131135            # this model and add it to the list to test.
    132             if not test_labels or model_name in set([label.split('.')[0] for label in test_labels]):
     136            # Also, skip the tests explicitely excluded by the user
     137            if not test_labels or model_name in test_labels_set:
     138                if model_name in exclude_labels:
     139                    if verbosity >= 1:
     140                        print "Skipping app %s" % model_name
     141                    continue
    133142                if verbosity >= 1:
    134143                    print "Importing model %s" % model_name
    135144                mod = load_app(model_label)
     
    153162            except ValueError:
    154163                pass
    155164
    156     # Run the test suite, including the extra validation tests.
     165    # Run the test suite, including the extra validation tests and skipping
     166    # the test explicitely excluded.
    157167    from django.test.utils import get_runner
    158168    if not hasattr(settings, 'TEST_RUNNER'):
    159169        settings.TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'
     
    198208        help='Tells Django to stop running the test suite after first failed test.')
    199209    parser.add_option('--settings',
    200210        help='Python path to settings module, e.g. "myproject.settings". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.')
     211    parser.add_option('-e', '--exclude', action='append', dest='exclude', default=[],
     212        help='Test to exclude (use multiple times to exclude multiple tests).')
    201213    options, args = parser.parse_args()
    202214    if options.settings:
    203215        os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
    204216    elif "DJANGO_SETTINGS_MODULE" not in os.environ:
    205217        parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. "
    206218                      "Set it or use --settings.")
    207     django_tests(int(options.verbosity), options.interactive, options.failfast, args)
     219    django_tests(int(options.verbosity), options.interactive, options.failfast, args, options.exclude)
Back to Top