Import error across entire Django project

885 views Asked by At

I am getting strange error in Django when trying to run tests:

[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)

This is strange, because I'm able to run the server in python2 or 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.

The testrunner fails for both python2 or 3.

The 4 modules showing up at import error all have an init.py file in them.

The venv was made with

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

Recreating the venv didn't help.

I use:

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

Last time I ran tests they passed. I don't know what caused the break.

1

There are 1 answers

0
halfer On

(Posted answer on behalf of the question author).

I incorrectly had an init file in the manage.py root level of my project. I was using a root level utils.py. Removing this bad file fixed it. He explains Running django tutorial tests fail - No module named polls.tests