为什么 Nose 看不到我的任何环境变量?

发布于 2024-08-21 20:11:27 字数 399 浏览 3 评论 0原文

我刚刚开始使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄荷→糖丶微凉 2024-08-28 20:11:27

正如 Alok 所说,Nose 不会从 django.db.backends.creation 调用 BaseDatabaseCreation.create_test_db('None') ,因此您需要手动设置此设置。

我无法让它发挥作用。

然而,我找到了NoseDjango。

安装 NoseDjango:

easy_install django-nose  

由于 django-nose 扩展了 Django 的内置测试命令,因此您应该将其添加到 settings.py 中的 INSTALLED_APPS 中:

INSTALLED_APPS = (
...
'django_nose',
...
)

然后在 settings.py 中设置 TEST_RUNNER:

TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

一旦设置了 NoseDjango,您就可以通过以下方式运行 Nose 测试:

manage.py test

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
铜锣湾横着走 2024-08-28 20:11:27

显然鼻子不调用 create_test_db() 在 django/db/backends/creation.py 中,因此您会看到此错误。只需将其设置为None,或自己调用该方法即可。不确定这个问题是否在最新版本的 Django 中得到修复。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文