在Django中执行Unittest

时间:2011-06-08 11:05:27

标签: python django unit-testing django-unittest

我为我的django视图编写了一个小单元测试。我的项目结构就像

项目名/

         apps/

              module1/
                      tests.py
              module2/
                      tests.py

这是我的目录结构我正在使用命令执行测试:

$ python manage.py test_coverage module1 module2 -v2

然后它很好地执行测试,但现在我已经改变了dir结构,我创建了一个新的目录test /,因为我保存了我的所有测试文件

PROJECT_NAME /

       apps/

            module1/
                    tests/
                         test_basic.py
                         test_detail.py

现在我可以使用相同的上述命令执行那些在dir中的测试,他们是执行此类测试的替代方法吗?

1 个答案:

答案 0 :(得分:3)

最简单的解决方案是将__init__.py文件添加到包含以下行的tests/包中:

from .test_basic import *
from .test_detail import *

然后运行所有测试:

$ python manage.py test module1