Ticket #12141: 12141.runtests_glob.diff

File 12141.runtests_glob.diff, 2.0 KB (added by Johannes Dollinger, 15 years ago)
  • tests/runtests.py

     
    11#!/usr/bin/env python
    22
    3 import os, sys, traceback
     3import os, sys, traceback, glob
    44import unittest
    55
    66import django.contrib as contrib
     
    8585        self.assert_(not unexpected, "Unexpected Errors: " + '\n'.join(unexpected))
    8686        self.assert_(not missing, "Missing Errors: " + '\n'.join(missing))
    8787
     88def collect_tests(*path):
     89    pattern = os.path.join(*path)
     90    labels = []
     91    for path in glob.glob(pattern):
     92        basename = os.path.basename(path)
     93        if "." not in basename:
     94            labels.append(basename)
     95    return labels
     96
    8897def django_tests(verbosity, interactive, test_labels):
    8998    from django.conf import settings
    9099
     100    tests_dir = os.path.dirname(__file__)
     101
     102    expanded_labels = []
     103    for label in test_labels:
     104        for pattern in label.split():
     105            if "/" in label:
     106                expanded_labels += collect_tests(tests_dir, pattern)
     107            else:
     108                expanded_labels += collect_tests(tests_dir, 'modeltests', pattern)
     109                expanded_labels += collect_tests(tests_dir, 'regressiontests', pattern)
     110    test_labels = expanded_labels
     111    if test_labels:
     112        print "Selected %s tests: %s" % (len(expanded_labels), ", ".join(expanded_labels))
     113
    91114    old_installed_apps = settings.INSTALLED_APPS
    92115    old_test_database_name = settings.TEST_DATABASE_NAME
    93116    old_root_urlconf = getattr(settings, "ROOT_URLCONF", "")
     
    100123    # Redirect some settings for the duration of these tests.
    101124    settings.INSTALLED_APPS = ALWAYS_INSTALLED_APPS
    102125    settings.ROOT_URLCONF = 'urls'
    103     settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), TEST_TEMPLATE_DIR),)
     126    settings.TEMPLATE_DIRS = (os.path.join(tests_dir, TEST_TEMPLATE_DIR),)
    104127    settings.USE_I18N = True
    105128    settings.LANGUAGE_CODE = 'en'
    106129    settings.LOGIN_URL = '/accounts/login/'
Back to Top