Django Unit tests issue : Import error

£可爱£侵袭症+ 提交于 2021-02-10 07:11:02

问题


I have the following project structure with Django 1.6:

DjangoMain
    - app_1
        - __init__.py
        - models.py
        - views.py
        - urls.py
        - test_views.py

If I run the following command my tests are processed without any issue by Django:

- python manage.py test app_1.test_views
Creating test database for alias 'default'...
.......
----------------------------------------------------------------------
Ran 7 tests in 1.436s

OK

But, when I want to run all my test in all my app using the global test command (without specifying an app) I have the following error:

- python manage.py test app_1
======================================================================
ERROR: DjangoMain.app_1.test_views (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: DjangoMain.app_1.test_views
Traceback (most recent call last):
File        "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 252, in _find_tests
module = self._get_module_from_name(name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 230, in _get_module_from_name
__import__(name) 
ImportError: No module named app_1.test_views

Has anyone an idea of what's going on with my project? It seems django is not able to find by himself the different tests to run. And I have absolutely no idea why.

来源:https://stackoverflow.com/questions/25141404/django-unit-tests-issue-import-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!