Python 在Django中执行Unittest
我已经为django视图编写了一个小单元测试 项目名称/Python 在Django中执行Unittest,python,django,unit-testing,django-unittest,Python,Django,Unit Testing,Django Unittest,我已经为django视图编写了一个小单元测试 项目名称/ apps/ module1/ tests.py module2/ tests.py apps/ module1/ tests/ test_basi
apps/
module1/
tests.py
module2/
tests.py
apps/
module1/
tests/
test_basic.py
test_detail.py
这是我的dir结构,我正在使用以下命令执行测试:
$python manage.py测试覆盖率模块1模块2-v2
然后它很好地执行了测试,但是现在我稍微改变了dir结构,我创建了一个新的目录tests/,其中保存了所有的测试文件
项目名称/
apps/
module1/
tests.py
module2/
tests.py
apps/
module1/
tests/
test_basic.py
test_detail.py
现在我可以用上面相同的命令执行那些在dir中的测试了,它们是否有其他方法来执行这些测试?最简单的解决方案是将
\uuuu init\uuuuuuuuuupy
文件添加到包含以下行的测试/
包中:
from .test_basic import *
from .test_detail import *
然后使用以下各项运行所有测试:
$ python manage.py test module1
最简单的解决方案是将
\uuuu init\uuuu.py
文件添加到包含以下行的tests/
包中:
from .test_basic import *
from .test_detail import *
然后使用以下各项运行所有测试:
$ python manage.py test module1
HyeŁukasz的作品…非常感谢。但是你能告诉我为什么和什么时候我们需要在导入文件时使用点(.)吗。@Shashi。HyeŁukasz的作品…非常感谢。但是你能告诉我为什么和什么时候我们需要在导入文件时使用点(.)吗。@Shashi。