Why does Nose not see any of my environmental variables?

萝らか妹 提交于 2019-12-11 07:53:02

问题


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:


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



回答2:


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.



来源:https://stackoverflow.com/questions/2240067/why-does-nose-not-see-any-of-my-environmental-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!