Friday, September 18, 2015

[newbie] import error after restart (virtualenv)

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
def home_page(request):
return HttpResponse('<html><title>To-Do lists</title></html>')

from django.core.urlresolvers import resolve
from django.test import TestCase
from django.http import HttpRequest

from lists.views import home_page

class HomePageTest(TestCase):

def test_root_url_resolves_to_home_page_view(self):
found = resolve('/')
self.assertEqual(found.func, home_page)

def test_home_page_returns_correct_html(self):
request = HttpRequest()
response = home_page(request)
self.assertTrue(response.content.startswith(b'<html>'))
self.assertIn(b'<title>To-Do lists</title>', response.content)
self.assertTrue(response.content.endswith(b'</html>'))

Dear Django experts,

I am reading through Harry Percival's "Test-Driven Development with
Python".

As I finished chapter 3 yesterday, I was fully on track, perfectly
aligned with the book.

Today I restarted my computer, activated the virtualenv in question --
and get an error message that was not there beforehand:

(Percival_TDD)david@lubuntu:~/PycharmProjects/Percival_TDD/superlists/lists$
python tests.py
Traceback (most recent call last):
File "tests.py", line 5, in <module>
from lists.views import home_page
ImportError: No module named 'lists'


I neither understand why he doesn't find 'lists' anymore nor do I know
how to solve the problem.

Can you please guide me towards a solution?

Thank you!

David



The project structure looks as follows:

(Percival_TDD)david@lubuntu:~/PycharmProjects/Percival_TDD/superlists$ tree
.
├── db.sqlite3
├── functional_tests.py
├── lists
│ ├── admin.py
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── manage.py
└── superlists
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-34.pyc
│ ├── settings.cpython-34.pyc
│ ├── urls.cpython-34.pyc
│ └── wsgi.cpython-34.pyc
├── settings.py
├── urls.py
└── wsgi.py


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/55FCA478.5000609%40gmx.net.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment