summaryrefslogtreecommitdiff
path: root/patches/NoseDjango-0.6.patch
blob: 625eccf0add2bf957c963bcf7e9ce1977e0060dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
--- nosedjango/nosedjango.py
+++ nosedjango/nosedjango.py
@@ -14,7 +14,10 @@ import nose.case
 # search the current working directory and all parent directories to find
 # the settings file
 from nose.importer import add_path
-os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+
+if 'DJANGO_SETTINGS_MODULE' not in os.environ:
+    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+
 import re
 NT_ROOT = re.compile(r"^[a-zA-Z]:\\$")
 def get_SETTINGS_PATH():
@@ -58,22 +61,9 @@ class NoseDjango(Plugin):
         connection over to that database. Then call install() to install
         all apps listed in the loaded settings module.
         """
-        # Add the working directory (and any package parents) to sys.path
-        # before trying to import django modules; otherwise, they won't be
-        # able to find project.settings if the working dir is project/ or
-        # project/..
-
-        if not SETTINGS_PATH:
-            sys.stderr.write("Can't find Django settings file!\n")
-            # short circuit if no settings file can be found
-            return
-
-        if self.conf.addPaths:
-            map(add_path, self.conf.where)
-
-        add_path(SETTINGS_PATH)
-        sys.path.append(SETTINGS_PATH)
-        import settings
+        # use dynamical import: we not necessary use settings.py
+        __import__(os.environ['DJANGO_SETTINGS_MODULE'])
+        settings = sys.modules[os.environ['DJANGO_SETTINGS_MODULE']]
 
         # Some Django code paths evaluate differently
         # between DEBUG and not DEBUG.  Example of this include the url