1

使用 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 看不到管理模块?

4

1 回答 1

2

显式导入managementapp

from app.management.commands.getevents import some_function

只是为了用一个工作示例证明我的话,检查如何在测试中导入自定义管理命令:django-compressor

from compressor.management.commands.compress import Command as CompressCommand
于 2014-04-26T20:40:37.753 回答