我正在使用Django==1.7c2
,但我不想对Django
进行查找,并在我的项目中运行所有测试。我只是使用__init__.py
创建了一个名为tests
的文件夹,而不是将所有文件夹都放入 tests.py 。
这是我的文件结构;
my_project/apps/my_app/
├── __init__.py
├── tests
├── __init__.py
├── my_first_test.py
├── my_second_test.py
├── ....
├── ....
└── ....
和我在测试文件中的__init__.py
像;from my_first_test import *
from my_second_test import *
我以为Django
最初会识别我的test folder
,但是当我只运行此命令时;python manage.py test
Django找不到要运行的测试用例。$ python manage.py test
Creating test database for alias 'default'...
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Destroying test database for alias 'default'...
我必须像我的项目中那样为特定应用程序运行测试;python manage.py test my_project.apps.my_app.tests
结果;----------------------------------------------------------------------
Ran 7 tests in 1.432s
OK
Destroying test database for alias 'default'...
我真的不喜欢它,因为我需要一次运行项目中所有应用程序中的所有测试,而不是一次一个地运行它们。我不知道我在想什么。是否可以说Django在项目中的所有应用程序中一次找到并运行所有测试?
谢谢你!
#编辑
我的
INSTALLED_APPS
中有setting.py
中的应用 最佳答案
试试这个:
$ ./manage.py test --pattern="*_test.py"
测试发现基于unittest模块的内置测试发现。默认情况下,这将在名为“test * .py”的任何文件中发现测试。
注意
顺便说一句,如果您使用的是标准测试发现,则无需在
__init__.py
文件中导入TestCases(Django从1.6开始使用内置的测试发现)关于python - Django一次运行所有测试,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25886016/