Background Image
Table of Contents Table of Contents
Previous Page  204 / 478 Next Page
Information
Show Menu
Previous Page 204 / 478 Next Page
Page Background

1. “Dunder” is shorthand for double-underscore, so “dunderinit” means

__init__.py

.

If you get a message saying “Ran 0 tests”, you probably forgot to add the dunderinit—

it needs to be there or else the tests folder isn’t a valid Python module…

1

Nowwe turn

test_all.py

into two files, one called

test_views.py

, which only contains view

tests, and one called

test_models.py

:

$

git mv lists/tests/test_all.py lists/tests/test_views.py

$

cp lists/tests/test_views.py lists/tests/test_models.py

We strip

test_models.py

down to being just the one test—it means it needs far fewer

imports:

lists/tests/test_models.py (ch10l009).

from

django.test

import

TestCase

from

lists.models

import

Item

,

List

class

ListAndItemModelsTest

(

TestCase

):

[

...

]

Whereas

test_views.py

just loses one class:

lists/tests/test_views.py (ch10l010).

--- a/lists/tests/test_views.py

+++ b/lists/tests/test_views.py

@@ -103,34 +104,3 @@ class ListViewTest(TestCase):

self.assertNotContains(response, 'other list item 1')

self.assertNotContains(response, 'other list item 2')

-

-

-class ListAndItemModelsTest(TestCase):

-

- def test_saving_and_retrieving_items(self):

[...]

We rerun the tests to check everything is still there:

$

python3 manage.py test lists

[...]

Ran 10 tests in 0.040s

OK

Great!

$

git add lists/tests

$

git commit -m "Split out unit tests into two files"

176

|

Chapter 10: Input Validation and Test Organisation