【发布时间】:2014-02-06 20:48:34
【问题描述】:
我有一个具有这种结构的 Django 应用程序:
app/
tests/
__init__.py
tests.py
__init__.py
test_model.py
在tests.py 中,我导入测试模型,例如:from app.test_model import *。这按预期工作:在测试期间,模型被加载,相应的数据库表被创建等等。
但是,如果我将test_model.py 文件移动到tests/ 目录中:
app/
tests/
__init__.py
test_model.py
tests.py
__init__.py
并相应地进行导入:from app.tests.test_model import *,它突然失败了。未检测到模型,因此未创建其数据库表并且测试开始失败 (DatabaseError: no such table: app_model)。
为什么会这样?我应该如何避免这种情况并仍然将test_model.py 文件放在tests/ 中?
【问题讨论】:
-
你使用的是什么版本的 Django?
-
我使用的是 Django 1.4.10
标签: python django testing python-import