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

标签 python django nose

我刚刚开始使用 Nose 和 Nosetests,但我的测试失败了,因为 Nose 看不到环境变量。

到目前为止,错误: AttributeError:“设置”对象没有属性“DJANGO_SETTINGS_MODULE”

我通过从 .bash_profile 导出 DJANGO_SETTINGS_MODULE 解决了这个问题

export DJANGO_SETTINGS_MODULE="settings"

现在我看到:
AttributeError:“设置”对象没有属性“DATABASE_SUPPORTS_TRANSACTIONS”

为什么 iPython 和 Django Web 服务器能够看到这些 ENV 变量,但 Nose 却不能?

最佳答案

正如 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

关于python - 为什么 Nose 看不到我的任何环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2240067/

相关文章:

python - pandas groupby 转置 str 列

python - Flask 中的 Popen 启动 Python 解释器

django - 在 Django 中构建每日新用户数列表

python - 如何从 django_nose 覆盖范围中排除代码的特定部分

python - 求解线性方程组

python - Django @login_required 在使用 nginx 和 fastcgi 时导致重定向循环

django - 有选择地删除上传到 Azure blob 的图像(Django/Python 项目)

Django,如何从模型形式的选择字段中删除空白选择?

python - 如果测试通过,我怎样才能包括额外的测试?

python - 原始输入处的 Nose 测试卡住