Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Django中执行Unittest_Python_Django_Unit Testing_Django Unittest - Fatal编程技术网

Python 在Django中执行Unittest

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

我已经为django视图编写了一个小单元测试

项目名称/

         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。