为什么鼻子看不到我的任何环境变量? [英] Why does Nose not see any of my environmental variables?
问题描述
我刚刚开始使用Nose和Nosetests,但由于鼻子看不到环境变量,所以我的测试失败了.
I'm just getting started using Nose and Nosetests and my tests are failing because Nose can't see the environmental variables.
到目前为止,这些错误: AttributeError:设置"对象没有属性"DJANGO_SETTINGS_MODULE"
So far, the errors: AttributeError: 'Settings' object has no attribute 'DJANGO_SETTINGS_MODULE'
我通过从.bash_profile中导出DJANGO_SETTINGS_MODULE来解决此问题
I fixed this by exporting DJANGO_SETTINGS_MODULE from .bash_profile
export DJANGO_SETTINGS_MODULE="settings"
现在我正在看到:
AttributeError:设置"对象没有属性"DATABASE_SUPPORTS_TRANSACTIONS"
Now I'm seeing:
AttributeError: 'Settings' object has no attribute 'DATABASE_SUPPORTS_TRANSACTIONS'
为什么iPython和Django网络服务器可以看到这些ENV变量,但鼻子看不到?
Why would iPython and the Django webserver be able to see these ENV variables, but Nose can't?
推荐答案
正如Alok所说,Nose不会从django.db.backends.creation调用BaseDatabaseCreation.create_test_db('None'),因此您需要设置此设置手动.
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.
我无法使它正常工作.
但是,我找到了NoseDjango.
However, I found NoseDjango.
使用以下命令安装NoseDjango:
Install NoseDjango with:
easy_install django-nose
由于django-nose扩展了Django的内置测试命令,因此应将其添加到settings.py中的INSTALLED_APPS中:
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',
...
)
然后在settings.py中设置TEST_RUNNER:
Then set TEST_RUNNER in settings.py:
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
一旦设置了NoseDjango,您就可以通过以下方式运行您的Nose测试:
Once NoseDjango is setup you can run your Nose tests via:
manage.py test
这篇关于为什么鼻子看不到我的任何环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!