django 1.6 app tests.py to tests子目录

时间:2014-04-26 20:39:04

标签: django django-testing django-1.6

使用django 1.6,我有一个带有tests.py文件的django应用程序

app
- tests.py

在这个文件中我测试了一些管理功能

from management.commands.getevents import some_function

当我尝试将tests.py更改为包含不同测试文件的测试目录时

app
- tests
-- __init__.py
-- test_models.py
-- test_views.py
-- test_managements.py

我尝试运行测试

python manage.py test

得到此错误

ImportError: Failed to import test module: events.tests.test_managements
...
ImportError: No module named management.commands...

用测试文件目录,为什么django看不到管理模块?

1 个答案:

答案 0 :(得分:2)

management明确导入app

from app.management.commands.getevents import some_function

只是用一个有效的例子证明我的话,检查how custom management command is imported测试中的django-compressor

from compressor.management.commands.compress import Command as CompressCommand