【发布时间】:2017-01-07 06:49:59
【问题描述】:
尝试运行测试时,我在 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.
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
我上次运行测试时他们通过了。我不知道是什么导致了中断。
【问题讨论】:
-
您是否删除了所有 *.pyc 文件以及所有子文件夹中的文件?
-
我现在试试
-
删除所有 .pyc,甚至是 pycache,都无济于事
标签: python django python-unittest django-unittest manage.py