Import error when unit testing with django.test.client on django 1.1.1

366 views
Skip to first unread message

Erlendur Hákonarson

unread,
Nov 23, 2011, 6:39:18 AM11/23/11
to django...@googlegroups.com
I am trying to set up unit tests on my project
but when I try to import anything from f.e. django.test
then I get this error:
Traceback (most recent call last):
  File "C:\eclipse\plugins\org.python.pydev.debug_2.2.2.2011082312\pysrc\pydev_runfiles.py", line 307, in __get_module_from_str
    mod = __import__(modname)
  File "C:/TFSSrc_Branch/DER_UnitTesting/bo/tests/testLists\Test.py", line 8, in <module>
    from django.test.Client import Client
  File "C:\TFSSrc_Branch\DER_UnitTesting\django\test\__init__.py", line 6, in <module>
    from django.test.testcases import TestCase
  File "C:\TFSSrc_Branch\DER_UnitTesting\django\test\testcases.py", line 10, in <module>
    from django.db import transaction
  File "C:\TFSSrc_Branch\DER_UnitTesting\django\db\__init__.py", line 9, in <module>
    if not settings.DATABASE_ENGINE:
  File "C:\TFSSrc_Branch\DER_UnitTesting\django\conf\__init__.py", line 28, in __getattr__
    self._import_settings()
  File "C:\TFSSrc_Branch\DER_UnitTesting\django\conf\__init__.py", line 59, in _import_settings
    self._target = Settings(settings_module)
  File "C:\TFSSrc_Branch\DER_UnitTesting\django\conf\__init__.py", line 94, in __init__
    raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'DER.settings' (Is it on sys.path? Does it have syntax errors?): No module named DER.settings
ERROR: Module: Test could not be imported (file: C:\TFSSrc_Branch\DER_UnitTesting\bo\tests\testLists\Test.py).

Here is my code:
import unittest
#from django.utils import unittest
from django.test.Client import Client

class TestLists(unittest.TestCase):

    def setUp(self):
        from django.test import Client
        self.client =  Client()
        self.client.login(username='erlendurh', password='e12345')

    def tearDown(self):
        pass

    def testGetList(self):
        self.client.get('/clearing/rep/contracts/from/2011-11-16/to/2011-11-26/')
        
if __name__ == "__main__":
    unittest.main()

I would be very glad if someone could help me with this problem :)

Best regards
Erlendur

xord...@linovia.com

unread,
Nov 23, 2011, 10:21:51 AM11/23/11
to django...@googlegroups.com
Hi

The error is:

> ImportError: Could not import settings 'DER.settings' (Is it on
> sys.path? Does it have syntax errors?): No module named DER.settings
> ERROR: Module: Test could not be imported (file:

> C:TFSSrc_BranchDER_UnitTestingboteststestListsTest.py).

You should google a bit on how to setup django tests with eclipse.
It looks like eclipse tests do not have your project in their paths
thus it doesn't find DER.settings.

Regards,
Xavier.

Erlendur Hákonarson

unread,
Nov 24, 2011, 7:18:03 AM11/24/11
to django...@googlegroups.com
Thanks Xavier
I will research this better
but the path for the settings file is wrong in this error, it should be 'bo.settings' not 'DER.settings'
but that might be because the tests do not have my project in their path

Thanks again
Erlendur
Reply all
Reply to author
Forward
0 new messages