背景:
我正在使用 Django 1.8。
我开始对其进行测试。
当我使用models.py
或views.py
时,我通常会删除它们,并创建一个同名的模块文件夹来替换。
通过这种方式,我可以将模型和 View 拆分到不同的代码文件中,并使它们易于编辑。
问题:
但是当我尝试将tests.py
更改为模块文件夹时,我发现__init__.py
中的测试用例无法运行。
怎么了?如果我想这样做,有什么办法吗?
请帮忙,谢谢。
最佳答案
来自docs :
Test discovery is based on the unittest module’s built-in test discovery. By default, this will discover tests in any file named “test*.py” under the current working directory.
所以我猜 __init__.py
中的测试不会被自动发现。
关于python - Django:tests.py 作为一个模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31757811/