Changeset 4206
- Timestamp:
- 12/15/06 00:06:52 (2 years ago)
- Files:
-
- django/trunk/tests/runtests.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/tests/runtests.py
r3708 r4206 41 41 models.append((loc, f)) 42 42 return models 43 43 44 44 class InvalidModelTestCase(unittest.TestCase): 45 45 def __init__(self, model_label): 46 46 unittest.TestCase.__init__(self) 47 47 self.model_label = model_label 48 48 49 49 def runTest(self): 50 50 from django.core import management … … 56 56 except Exception, e: 57 57 self.fail('Unable to load invalid model module') 58 58 59 59 s = StringIO() 60 60 count = management.get_validation_errors(s, module) … … 72 72 def django_tests(verbosity, tests_to_run): 73 73 from django.conf import settings 74 from django.db.models.loading import get_apps, load_app75 74 76 75 old_installed_apps = settings.INSTALLED_APPS … … 78 77 old_root_urlconf = settings.ROOT_URLCONF 79 78 old_template_dirs = settings.TEMPLATE_DIRS 80 79 old_use_i18n = settings.USE_I18N 80 81 81 # Redirect some settings for the duration of these tests 82 82 settings.TEST_DATABASE_NAME = TEST_DATABASE_NAME … … 84 84 settings.ROOT_URLCONF = 'urls' 85 85 settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), TEST_TEMPLATE_DIR),) 86 87 # load all the ALWAYS_INSTALLED_APPS 86 settings.USE_I18N = True 87 88 # Load all the ALWAYS_INSTALLED_APPS. 89 # (This import statement is intentionally delayed until after we 90 # access settings because of the USE_I18N dependency.) 91 from django.db.models.loading import get_apps, load_app 88 92 get_apps() 89 93 90 94 # Load all the test model apps 91 95 test_models = [] 92 for model_dir, model_name in get_test_models(): 96 for model_dir, model_name in get_test_models(): 93 97 model_label = '.'.join([model_dir, model_name]) 94 98 try: 95 99 # if the model was named on the command line, or 96 # no models were named (i.e., run all), import 100 # no models were named (i.e., run all), import 97 101 # this model and add it to the list to test. 98 102 if not tests_to_run or model_name in tests_to_run: … … 100 104 print "Importing model %s" % model_name 101 105 mod = load_app(model_label) 102 settings.INSTALLED_APPS.append(model_label) 106 settings.INSTALLED_APPS.append(model_label) 103 107 test_models.append(mod) 104 108 except Exception, e: 105 109 sys.stderr.write("Error while importing %s:" % model_name + ''.join(traceback.format_exception(*sys.exc_info())[1:])) 106 continue 110 continue 107 111 108 112 # Add tests for invalid models … … 112 116 if not tests_to_run or model_name in tests_to_run: 113 117 extra_tests.append(InvalidModelTestCase(model_label)) 114 118 115 119 # Run the test suite, including the extra validation tests. 116 120 from django.test.simple import run_tests 117 121 run_tests(test_models, verbosity, extra_tests=extra_tests) 118 122 119 123 # Restore the old settings 120 124 settings.INSTALLED_APPS = old_installed_apps … … 122 126 settings.ROOT_URLCONF = old_root_urlconf 123 127 settings.TEMPLATE_DIRS = old_template_dirs 124 128 settings.USE_I18N = old_use_i18n 129 125 130 if __name__ == "__main__": 126 131 from optparse import OptionParser … … 129 134 parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='0', 130 135 type='choice', choices=['0', '1', '2'], 131 help='Verbosity level; 0=minimal output, 1=normal output, 2=all output') 136 help='Verbosity level; 0=minimal output, 1=normal output, 2=all output') 132 137 parser.add_option('--settings', 133 138 help='Python path to settings module, e.g. "myproject.settings". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.') … … 135 140 if options.settings: 136 141 os.environ['DJANGO_SETTINGS_MODULE'] = options.settings 137 142 138 143 django_tests(int(options.verbosity), args)
