Code

Ticket #6298: 6298.diff

File 6298.diff, 1.9 KB (added by robhudson, 4 years ago)

Updated patch after multidb

Line 
1diff --git a/tests/runtests.py b/tests/runtests.py
2index f2ea5f1..978281b 100755
3--- a/tests/runtests.py
4+++ b/tests/runtests.py
5@@ -3,13 +3,16 @@
6 import os, sys, traceback
7 import unittest
8 
9-import django.contrib as contrib
10+# tests should use the same version (as has been checked out)
11+if sys.argv:
12+    script_path = os.path.dirname(sys.argv[0])
13+    django_path = os.path.abspath(os.path.join(script_path, ".."))
14+    sys.path.insert(1, django_path)
15 
16-try:
17-    set
18-except NameError:
19-    from sets import Set as set     # For Python 2.3
20+import django
21+import django.contrib as contrib
22 
23+print "\nRunning tests against " + os.path.dirname(django.__file__)
24 
25 CONTRIB_DIR_NAME = 'django.contrib'
26 MODEL_TESTS_DIR_NAME = 'modeltests'
27@@ -190,6 +193,23 @@ if __name__ == "__main__":
28     if options.settings:
29         os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
30     elif "DJANGO_SETTINGS_MODULE" not in os.environ:
31-        parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. "
32-                      "Set it or use --settings.")
33+        # since no settings have been defined, set up a test env using SQLite
34+        try:
35+            import sqlite3
36+            from django.conf import settings
37+            settings.configure(**{
38+                'DATABASES': {
39+                    'default': {
40+                        'ENGINE': 'django.db.backends.sqlite3'
41+                    },
42+                    'other': {
43+                        'ENGINE': 'django.db.backends.sqlite3',
44+                        'TEST_NAME': 'other_db'
45+                    }
46+                },
47+                'ROOT_URLCONF': '/',
48+            })
49+        except ImportError:
50+            parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. "
51+                          "Set it or use --settings.")
52     django_tests(int(options.verbosity), options.interactive, options.failfast, args)