Ticket #12141: 12141.runtests_glob.diff
File 12141.runtests_glob.diff, 2.0 KB (added by , 15 years ago) |
---|
-
tests/runtests.py
1 1 #!/usr/bin/env python 2 2 3 import os, sys, traceback 3 import os, sys, traceback, glob 4 4 import unittest 5 5 6 6 import django.contrib as contrib … … 85 85 self.assert_(not unexpected, "Unexpected Errors: " + '\n'.join(unexpected)) 86 86 self.assert_(not missing, "Missing Errors: " + '\n'.join(missing)) 87 87 88 def 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 88 97 def django_tests(verbosity, interactive, test_labels): 89 98 from django.conf import settings 90 99 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 91 114 old_installed_apps = settings.INSTALLED_APPS 92 115 old_test_database_name = settings.TEST_DATABASE_NAME 93 116 old_root_urlconf = getattr(settings, "ROOT_URLCONF", "") … … 100 123 # Redirect some settings for the duration of these tests. 101 124 settings.INSTALLED_APPS = ALWAYS_INSTALLED_APPS 102 125 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),) 104 127 settings.USE_I18N = True 105 128 settings.LANGUAGE_CODE = 'en' 106 129 settings.LOGIN_URL = '/accounts/login/'