开发者

Why does Nose not see any of my environmental variables?

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 at开发者_C百科tribute '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?


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.NoseTestSuiteRunner'

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

manage.py test


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜