Django 测试找不到我的测试

Ale*_*lla 4 django django-tests

当我运行测试时,django 运行 0 个测试。这是我的项目结构:

manage.py
- app/
  - main_app/
    - test/
       - tests_v1.py
       - tests_v2.py
Run Code Online (Sandbox Code Playgroud)

我使用这个命令:

python manage.py test --pattern="tests_v*.py"
Run Code Online (Sandbox Code Playgroud)

Django 在 0 秒内运行 0 个测试。我错过了什么?

itz*_*nTV 6

__init__.py在里面添加文件test目录中。然后将所有内容导入其中

__init__.py

from tests_v1 import *
from tests_v2 import *
Run Code Online (Sandbox Code Playgroud)

笔记

命名tests_v1tests_v1.py

  • django 的测试运行器将根据文件名模式发现测试,因此无需在 `__init__.py` 中导入 (3认同)
  • 是的,文件 `__init__.py` 是必需的,但不需要在其中导入。 (2认同)