Chapter 5: Unexpected error in lists/tests.py

323 views
Skip to first unread message

Богдан Сиващенко

unread,
Jul 31, 2019, 9:38:22 AM7/31/19
to Obey the testing goat! Test-Driven Web Development with Python book
Hello everybody,
My name is Bohdan and I'm new to Django.
I've got a strange error while modifying lists/test.py. Here is what i get when I run it:

$python3 manage.py test
Creating test database for alias 'default'...
E
======================================================================
ERROR: lists.tests (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: lists.tests
Traceback (most recent call last):
  File "/usr/lib/python3.7/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/bohdan/Documents/TG_01/superlists/lists/tests.py", line 4, in <module>
    from django.template.loader import render_to_srting
ImportError: cannot import name 'render_to_srting' from 'django.template.loader' (/usr/local/lib/python3.7/dist-packages/django/template/loader.py)

I can't imagine what am I doing wrong. I would be grateful if somebody could help me.

Arnie Elkins

unread,
Jul 31, 2019, 2:41:46 PM7/31/19
to Obey the testing goat! Test-Driven Web Development with Python book
I do not know your code, but the ImportError at the top of the error output says it cannot find your module lists.tests.  You stated that you were modifying lists.test.py.  This seems to indicate that the file should be tests.py instead of test.py, or you reference to import is should be lists.test.

Did you try this before you modified the lists/test.py module? Did a name get changed somewhere?

Arnie Elkins

unread,
Jul 31, 2019, 2:47:57 PM7/31/19
to Obey the testing goat! Test-Driven Web Development with Python book
Another note (apparently it IS finding the tests.py file): The ImportError has what could be a typo. It is looking for "render_to_srting", instead of what I assume you meant, "render_to_string". This of course causes it to fail the import, because the one you typed does not exist.


On Wednesday, July 31, 2019 at 1:41:46 PM UTC-5, Arnie Elkins wrote:
I do not know your code, but the ImportError at the top of the error output says it cannot find your module lists.tests.  You stated that you were modifying lists.test.py.  This seems to indicate that the file should be tests.py instead of test.py, or you reference to import is should be lists.test.

Did you try this before you modified the lists/test.py module? Did a name get changed somewhere?

On Wednesday, July 31, 2019 at 8:38:22 AM UTC-5, Богдан Сиващенко wrote:
Hello everybody,
My name is Bohdan and I'm new to Django.
I've got a strange error while modifying lists/test.py. Here is what i get when I run it:

$python3 manage.py test
Creating test database for alias 'default'...
E
======================================================================
ERROR: lists.tests (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: lists.tests
Traceback (most recent call last):
  File "/usr/lib/python3.7/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/bohdan/Documents/TG_01/superlists/lists/tests.py", line 4, in <module>
    from django.template.loader import render_to_srting
ImportError: cannot import name y",from 'django.template.loader' (/usr/local/lib/python3.7/dist-packages/django/template/loader.py)

Богдан Сиващенко

unread,
Aug 1, 2019, 3:40:22 AM8/1/19
to Obey the testing goat! Test-Driven Web Development with Python book
Yes, the problem was in "render_to_srting". It was just a typo(as I am using Pluma notebook without linter, which could help). And I made another typo while writing first message here, yes the modified file is lists/tests.py. Thank you very much for your help.

среда, 31 июля 2019 г., 21:47:57 UTC+3 пользователь Arnie Elkins написал:
Another note (apparently it IS finding the tests.py file): The ImportError has what could be a typo. It is looking for "render_to_srting", instead of what I assume you meant, "render_to_string". This of course causes it to fail the import, because the one you typed does not exist.

On Wednesday, July 31, 2019 at 1:41:46 PM UTC-5, Arnie Elkins wrote:
I do not know your code, but the ImportError at the top of the error output says it cannot find your module lists.tests.  You stated that you were modifying lists.test.py.  This seems to indicate that the file should be tests.py instead of test.py, or you reference to import is should be lists.test.

Did you try this before you modified the lists/test.py module? Did a name get changed somewhere?

On Wednesday, July 31, 2019 at 8:38:22 AM UTC-5, Богдан Сиващенко wrote:
Hello everybody,
My name is Bohdan and I'm new to Django.
I've got a strange error while modifying lists/tests.py. Here is what i get when I run it:
Reply all
Reply to author
Forward
0 new messages