So, I haven't had this problem specifically, but all the tests I've
written don't make changes to DJANGO_PATH or os.environ. I believe the
test runner takes care of this automatically.

If your tests are in project/app/tests.py

and you're running them with:

python manage.py test

you should be ok if you remove the path/environ lines.

On Oct 10, 11:51 am, Karthik Krishnan <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am trying to run a unit test for my models. My unit test is as
> follows
>
> import os
> import unittest
> from myproject import models
>
> DJANGO_PATH = "DJANGO_SETTINGS_MODULE"
> os.environ[DJANGO_PATH] = "myproject.settings"
>
> class ModelsTestCase(unittest.TestCase):
>   user = None
>
>   def setUp(self):
>     self.user = models.User.create(first_name='Krishnan',
> last_name='Karthik')
>
>   def testUserInstantiation(self):
>     self.failIfEqual(self.user, None, "Failure to initialize")
>
> I always get this error:
>
>  line 57, in _import_settings
>     raise ImportError("Settings cannot be imported, because
> environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
> ImportError: Settings cannot be imported, because environment variable
> DJANGO_SETTINGS_MODULE is undefined.
>
> This is inspite of the setting the environment settings on top of the
> test case. Please let me know if i am doing anything wrong.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to