Ticket #6298: runtests.patch
File runtests.patch, 1.7 KB (added by , 17 years ago) |
---|
-
runtests.py
3 3 import os, sys, traceback 4 4 import unittest 5 5 6 # if settings aren't set, try settings up a test environment that uses SQLite 7 fakesettings = None 8 if not os.environ.get("DJANGO_SETTINGS_MODULE", None): 9 try: 10 import sqlite3 # is SQLite available? 11 from types import ModuleType 12 fakesettings = ModuleType("settings", "A fake settings module that can be used to run django tests with sqlite3" ) 13 fakesettings.DATABASE_ENGINE = "sqlite3" 14 fakesettings.ROOT_URLCONF = "/" 15 fakesettings.__file__ = os.path.join(os.path.abspath("."),"fakesettings") 16 except: 17 pass 18 19 20 # tests should use the same version (as has been checked out) 21 if len(sys.argv): 22 script_path = os.path.dirname(sys.argv[0]) 23 django_path = os.path.abspath(os.path.join(script_path, "..")) 24 sys.path.insert(1, django_path) 25 26 import django 6 27 import django.contrib as contrib 7 28 29 print "\nRunning tests against " + os.path.dirname(django.__file__) 30 8 31 try: 9 32 set 10 33 except NameError: … … 172 195 options, args = parser.parse_args() 173 196 if options.settings: 174 197 os.environ['DJANGO_SETTINGS_MODULE'] = options.settings 198 elif fakesettings: # this won't be available if DJANGO_SETTINGS_MODULE has been set 199 os.environ["DJANGO_SETTINGS_MODULE"] = "settings" 200 sys.modules["settings"] = fakesettings 175 201 elif "DJANGO_SETTINGS_MODULE" not in os.environ: 176 202 parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. " 177 203 "Set it or use --settings.")