tests.py is the conventional Django application module for unit tests. Django creates it when you create an app, usually with an import for django.test.TestCase. section 2.3 section 8.2
A test class inherits from TestCase and defines methods whose names begin with test_. Django’s test client exercises the application without opening a real browser. section 8.2 section 8.2
Testing a view
In home/tests.py, TestHome can call self.client.get("/credits/") and check response.status_code with self.assertEqual(200, response.status_code). Running python manage.py test discovers and executes the test, reporting success or failure. section 8.2 section 8.2
Listing 8.1 A test case for the credits() view
# home/tests.py
from django.test import TestCase #1
class TestHome(TestCase): #2
def test_credits(self): #3
response = self.client.get("/credits/") #4
self.assertEqual(200, response.status_code) #5
Shows the complete tests.py listing, including TestCase inheritance, client request, and status assertion. section 8.2
