为什么 Nose 看不到我的任何环境变量?
我刚刚开始使用 Nose 和 Nosetests,但我的测试失败了,因为 Nose 看不到环境变量。
到目前为止,错误: AttributeError:“设置”对象没有属性“DJANGO_SETTINGS_MODULE”
我通过从 .bash_profile 导出 DJANGO_SETTINGS_MODULE 修复了此问题
export DJANGO_SETTINGS_MODULE="settings"
现在我看到:
AttributeError: 'Settings' 对象没有属性 'DATABASE_SUPPORTS_TRANSACTIONS'
为什么 iPython 和 Django Web 服务器能够看到这些 ENV 变量,但 Nose 不能?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Alok 所说,Nose 不会从 django.db.backends.creation 调用 BaseDatabaseCreation.create_test_db('None') ,因此您需要手动设置此设置。
我无法让它发挥作用。
然而,我找到了NoseDjango。
安装 NoseDjango:
由于 django-nose 扩展了 Django 的内置测试命令,因此您应该将其添加到 settings.py 中的 INSTALLED_APPS 中:
然后在 settings.py 中设置 TEST_RUNNER:
一旦设置了 NoseDjango,您就可以通过以下方式运行 Nose 测试:
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:
Since django-nose extends Django's built-in test command, you should add it to your INSTALLED_APPS in settings.py:
Then set TEST_RUNNER in settings.py:
Once NoseDjango is setup you can run your Nose tests via:
显然鼻子不调用
create_test_db() 在
django/db/backends/creation.py
中,因此您会看到此错误。只需将其设置为None
,或自己调用该方法即可。不确定这个问题是否在最新版本的 Django 中得到修复。Apparently nose doesn't call
create_test_db()
indjango/db/backends/creation.py
, so you are seeing this error. Just set it toNone
, or call the method yourself. Not sure if this is fixed in a recent version of Django.