Question

I'm just getting started using Nose and Nosetests and my tests are failing because Nose can't see the environmental variables.

So far, the errors: AttributeError: 'Settings' object has no attribute 'DJANGO_SETTINGS_MODULE'

I fixed this by exporting DJANGO_SETTINGS_MODULE from .bash_profile

export DJANGO_SETTINGS_MODULE="settings"

Now I'm seeing:
AttributeError: 'Settings' object has no attribute 'DATABASE_SUPPORTS_TRANSACTIONS'

Why would iPython and the Django webserver be able to see these ENV variables, but Nose can't?

Was it helpful?

Solution

As Alok said, Nose doesn't call BaseDatabaseCreation.create_test_db('None') from django.db.backends.creation so you will need to set this setting manually.

I was not able to get that to work.

However, I found NoseDjango.

Install NoseDjango with:

easy_install django-nose  

Since django-nose extends Django's built-in test command, you should add it to your INSTALLED_APPS in settings.py:

INSTALLED_APPS = (
...
'django_nose',
...
)

Then set TEST_RUNNER in settings.py:

TEST_RUNNER = 'django_nose.run_tests'

Once NoseDjango is setup you can run your Nose tests via:

manage.py test

OTHER TIPS

Apparently nose doesn't call create_test_db() in django/db/backends/creation.py, so you are seeing this error. Just set it to None, or call the method yourself. Not sure if this is fixed in a recent version of Django.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top