ImportError: No module named 'superlists.lists'
So... starting to work my way thru the book 'Test Driven Development with Python' and I'm trying (against the author's recommendations) to do it using an IDE, namely PyCharm.
I got the first functional test working (using selenium and unittest), but when I got to the part for tests.py I started having problems.
My directory structure looks like this:
superlists/
├── db.sqlite3
├── functional_tests.py
├── __init__.py
├── lists
│ ├── admin.py
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── manage.py
├── superlists
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── templates
When I click 'Tools > Run manage.py Task > test' (and select 'All applications') the test fails. At this point in the text, it is actually supposed to fail, just not like this:
Maybe I'm missing something elementary... but it seems pretty obvious that there is a module 'superlists.lists', as created by PyCharm itself. Using Python 3.4.0 on Ubuntu 14.04, in a virtualenv, with just pip, setuptools, django 1.7 and selenium installed in the virtualenv.
Any ideas/hints?
Thanks,
Monte
I got the first functional test working (using selenium and unittest), but when I got to the part for tests.py I started having problems.
My directory structure looks like this:
superlists/
├── db.sqlite3
├── functional_tests.py
├── __init__.py
├── lists
│ ├── admin.py
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── manage.py
├── superlists
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── templates
When I click 'Tools > Run manage.py Task > test' (and select 'All applications') the test fails. At this point in the text, it is actually supposed to fail, just not like this:
Code
Error Traceback (most recent call last): File "/usr/lib/python3.4/unittest/case.py", line 57, in testPartExecutor yield File "/usr/lib/python3.4/unittest/case.py", line 574, in run testMethod() File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure raise exception ImportError: Failed to import test module: superlists.lists.tests Traceback (most recent call last): File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests module = self._get_module_from_name(name) File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name __import__(name) ImportError: No module named 'superlists.lists'
Maybe I'm missing something elementary... but it seems pretty obvious that there is a module 'superlists.lists', as created by PyCharm itself. Using Python 3.4.0 on Ubuntu 14.04, in a virtualenv, with just pip, setuptools, django 1.7 and selenium installed in the virtualenv.
Any ideas/hints?
Thanks,
Monte
Please sign in to leave a comment.
Then I recreated the entire project again from the command line using django-admin.py, side-by-side with a slightly different name (supperlist) and tried again - and got the results I expected i.e. the test inside tests.py ran (failed, as they were supposed to at this point, but they ran).
I listed both directories in separate windows using the 'tree' command in each... and the only significant difference was that there was an extra __init__.py in the top level folder 'superlist' (the one created by pycharm) that was not there in 'supperlist' (the one created manually using django-admin.py. The only thing in the file was one line:
I renamed that file temporarily and re-ran 'python manage.py test' - and it worked as it should.
Not sure why that __init__.py in that location would screw up loading tests.py from inside /lists...?
.
├── functional_tests.py
└── superlists
├── db.sqlite3
├── lists
│ ├── __init__.py
│ ├── admin.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── templates
│ │ └── home.html
│ ├── tests.py
│ └── views.py
├── manage.py
└── superlists
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
If I run now within PyCharm manage.py test I get this error:
If I run this straight from the shell without (!!!) changing the code the tests passes:
Looks like PyCharm is messing up the Django folders?
EDIT:
Just found several bugs in the bug tracker linked to this issue. Will probably be fixed in build 140.792