---
django: 6.1.3 (f16e25dcb9fe55734ba4ea2b00ac34405b7df74a)
part: In practice
promise: Tests run in a clean copy of your app.
contents: commands, checks, autoreload, test-databases, testcase-rollbacks, test-client
---

# Commands, checks, and testing

How `manage.py` discovers commands, how system checks guard startup, why the autoreloader spawns a child process, and how `TestCase` uses transaction rollbacks instead of recreating tables.

Part IV steps outside the HTTP request handler into the terminal workflow every Django engineer lives in all day: `manage.py`, system checks, the development server's autoreloader, and Django's test suite. Because running `"manage.py test"` finishes in milliseconds and leaves the database untouched between test methods, it feels like every test runs inside a freshly cloned copy of your application.

Open the source and the illusion dissolves into four clever pieces of engineering — each with sharp boundaries you need to know when a test passes locally and fails in production. `ManagementUtility` (`django/core/management/__init__.py:ManagementUtility`) discovers commands in reverse `"INSTALLED_APPS"` order and guards `BaseCommand.execute` (`django/core/management/base.py:BaseCommand.execute`) with `CheckRegistry` (`django/core/checks/registry.py:CheckRegistry`), whose `"--deploy"` security checks never run during normal development. `run_with_reloader` (`django/utils/autoreload.py:run_with_reloader`) spawns a parent supervisor and child worker (invoking `AppConfig.ready` twice!). `TestCase` (`django/test/testcases.py:TestCase`) achieves a `20x` speedup over `TransactionTestCase` (`django/test/testcases.py:TransactionTestCase`) by wrapping each class in an uncommitted outer transaction and rolling back an inner savepoint after every test — which is why `django.db.transaction.on_commit` callbacks never fire unless captured explicitly! And `ClientHandler` (`django/test/client.py:ClientHandler`) runs your full WSGI middleware stack with zero sockets while quietly disabling CSRF enforcement by default.

## Why `TestCase` is 20x faster than `TransactionTestCase`

```text figure=testcase-rollback-vs-flush
TestCase savepoint rollback vs TransactionTestCase table flush on desk/ (Django 6.1.3, 5 trials)

1. How TestCase avoids flushing tables — and why on_commit does not fire:
   TestCase:            setUpClass() BEGIN outer tx + setUpTestData() once -> per-test SAVEPOINT -> ROLLBACK TO SAVEPOINT
                        outer tx NEVER commits -> use captureOnCommitCallbacks(execute=True)!
   TransactionTestCase: autocommit mode -> real COMMIT per test -> call_command('flush') across every table after each test

2. Running 15 test methods on desk/ (5 trials, median ms):
   TransactionTestCase (flush/test)   178.03 ms  (  1.00x baseline)
   TestCase (savepoint rollback)        8.62 ms  ( 20.65x faster)
   SimpleTestCase (no DB access)        0.42 ms  (429.00x faster)
```

*Every timing bar and isolation fact is parsed directly from `ch13-tooling` and `ch13-bench`. Rolling back an inner savepoint takes microseconds compared to flushing every table and re-seeding fixtures after every test (`8.62 ms` vs. `178.03 ms` over 15 DB tests, **`20.65x` faster**) — and `SimpleTestCase` skips database setup altogether (`0.42 ms`, **`429x` faster**)!*

## The developer terminal loop in six stops

First we trace `execute_from_command_line` (`django/core/management/__init__.py:execute_from_command_line`) into `BaseCommand` (`django/core/management/base.py:BaseCommand`), then separate static checks from `"--deploy"` and `"database"` checks inside `CheckRegistry`. Next we open `StatReloader` (`django/utils/autoreload.py:StatReloader`) and `restart_with_reloader` (`django/utils/autoreload.py:restart_with_reloader`) to explain why `"runserver"` runs two processes.

Then we dissect Django's entire test stack: `DiscoverRunner` (`django/test/runner.py:DiscoverRunner`) and `BaseDatabaseCreation` (`django/db/backends/base/creation.py:BaseDatabaseCreation`) database creation and cloning, the exact nested transaction mechanics separating `SimpleTestCase`, `TestCase`, and `TransactionTestCase`, and how `Client` (`django/test/client.py:Client`) and `RequestFactory` (`django/test/client.py:RequestFactory`) differ from production `WSGIHandler`.

We start at the command line in [manage.py, discovery, and BaseCommand](tooling/commands.md).
