views:

218

answers:

2

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?

+1  A: 

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.

Alok
from django.db.backends.creation import BaseDatabaseCreation; BaseDatabaseCreation.create_test_db('None') # did not work
BryanWheelock
settings in the tests.py: DATABASE_SUPPORTS_TRANSACTIONS = None # did not work either
BryanWheelock
I don't know or use Django, but a google search shows http://github.com/inoi/nosedjango/commit/45e9dbd4e59896ae9160e029d92854ce37f4877d, which looks like what you want.
Alok
+1  A: 

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
BryanWheelock