Ticket #6298: runtests.patch

File runtests.patch, 1.7 KB (added by curtis@…, 17 years ago)
  • runtests.py

     
    33import os, sys, traceback
    44import unittest
    55
     6# if settings aren't set, try settings up a test environment that uses SQLite
     7fakesettings = None
     8if 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)
     21if 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
     26import django
    627import django.contrib as contrib
    728
     29print "\nRunning tests against " + os.path.dirname(django.__file__)
     30
    831try:
    932    set
    1033except NameError:
     
    172195    options, args = parser.parse_args()
    173196    if options.settings:
    174197        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
    175201    elif "DJANGO_SETTINGS_MODULE" not in os.environ:
    176202        parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. "
    177203                      "Set it or use --settings.")
Back to Top