整个Django项目导入错误

时间:2017-01-07 06:49:59

标签: python django python-unittest django-unittest manage.py

我在尝试运行测试时在Django中遇到奇怪的错误:

[homebrewpython3] cchilders:~/projects/homebrew_app (CKC/finish-db-update-script) 
$ python manage.py test
Creating test database for alias 'default'...
EEEE
======================================================================
ERROR: homebrew_app.api (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: homebrew_app.api
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/loader.py", line 462, in _find_test_path
    package = self._get_module_from_name(name)
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/loader.py", line 369, in _get_module_from_name
    __import__(name)
ImportError: No module named 'homebrew_app.api'


======================================================================
ERROR: homebrew_app.calculations (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: homebrew_app.calculations
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/loader.py", line 462, in _find_test_path
    package = self._get_module_from_name(name)
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/loader.py", line 369, in _get_module_from_name
    __import__(name)
ImportError: No module named 'homebrew_app.calculations'


======================================================================
ERROR: homebrew_app.homebrew_app (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: homebrew_app.homebrew_app
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/loader.py", line 462, in _find_test_path
    package = self._get_module_from_name(name)
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/loader.py", line 369, in _get_module_from_name
    __import__(name)
ImportError: No module named 'homebrew_app.homebrew_app'


======================================================================
ERROR: homebrew_app.main (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: homebrew_app.main
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/loader.py", line 462, in _find_test_path
    package = self._get_module_from_name(name)
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/loader.py", line 369, in _get_module_from_name
    __import__(name)
ImportError: No module named 'homebrew_app.main'


----------------------------------------------------------------------
Ran 4 tests in 0.000s

FAILED (errors=4)

这很奇怪,因为我能够在python2或3中运行服务器:

$ rs
System check identified 1 issue (0 silenced).
January 07, 2017 - 06:45:01
Django version 1.10.5, using settings 'homebrew_app.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

testrunner对python2或3都失败了。

出现导入错误的4个模块都包含 init .py文件。

venv是用

制作的
mkvirtualenv -p `which python3` homebrew_app
pip3 install -r requirements.txt 

重新创建venv并没有帮助。

我用:

django
django-cors-headers
django-extensions
djangorestframework
Faker
gunicorn
ipdb
ipython
mysqlclient
requests
PyYaml

上次我进行了测试,他们通过了。我不知道导致休息的原因。

1 个答案:

答案 0 :(得分:-1)

(代表作者提问回答)

我错误地在项目的init根级别中有一个manage.py文件。我使用的是根级utils.py。删除此错误文件修复它。他解释了Running django tutorial tests fail - No module named polls.tests