CodeVetter · Repo Unpack · Testing signals
django/django
Django tests Django with its own test runner. The suite lives in tests/ and is launched by tests/runtests.py, not by a third-party discovery command. Default CI is SQLite on CPython 3.14 plus a free-threading job; JavaScript admin tests and scripts/ unit tests are separate jobs. Lint is flake8, isort, black, and zizmor. Postgres, MySQL, Oracle, and PostGIS need extra settings and are not what tox runs by default. Deprecation and resource warnings are treated as errors, so a behavior change that trips RemovedInNextVersionWarning fails the suite.
- tests/runtests.py imports django.test.TestCase, TransactionTestCase, and get_runner (TEST_RUNNER default django.test.runner.DiscoverRunner). It filters RemovedInNextVersionWarning, RemovedAfterNextVersionWarning, ResourceWarning, and RuntimeWarning as errors, and raises GC thresholds on CPython.
- Discovery scans tests/ for packages containing __init__.py. SUBDIRS_TO_SKIP always skips import_error_package, playwright_tests, and test_runner_apps. gis_tests is skipped unless GIS is enabled, and gis_tests/data is always skipped. The documented invocation is cd tests && ./runtests.py after pip install -e .. and tests/requirements/py3.txt.
- The runner always installs contenttypes, auth, sites, sessions, messages, django.contrib.admin.apps.SimpleAdminConfig, and staticfiles, and always enables SessionMiddleware, CommonMiddleware, CsrfViewMiddleware, AuthenticationMiddleware, and MessageMiddleware. flatpages and redirects are added only for their test labels.
- tox default environments are py3, black, blacken-docs, flake8, docs, isort, lint-docs, and zizmor. Database factors such as postgres, mysql, and oracle append extra requirements but still need a settings module the suite does not vendor, for example tox -e py312-postgres -- --settings=my_postgres_settings. Free-threaded envs py314t and py313t exist.
- .github/workflows/tests.yml on pull_request and push to main (ignoring docs/**) runs python -Wall tests/runtests.py -v2 for Windows/SQLite/Python 3.14 and Ubuntu/SQLite/Python 3.14t, npm test for admin JavaScript, and python -m unittest discover -v -s scripts/.
- JavaScript coverage is QUnit via Grunt: package.json scripts.test is grunt test --verbose, devDependencies include qunit, grunt-contrib-qunit, and @biomejs/biome. Test files live under js_tests/admin (actions, DateTimeShortcuts, inlines, SelectBox, URLify) and js_tests/gis/mapwidget.test.js.
- Linters workflow runs flake8, isort --check --diff django tests scripts, black (psf/black@stable), and zizmor. pyproject.toml configures black target-version py312 and isort profile black with known_first_party django.
- Playwright browser tests are label-gated: .github/workflows/playwright.yml runs only when the pull request has the playwright label, then installs apt packages and Playwright browsers. runtests.py imports PlaywrightTestCase but does not discover tests/playwright_tests during the normal scan.
- Topic packages under tests/ include auth_tests, csrf_tests, handlers, migrations-related packages, admin_views, forms_tests, gis_tests, composite_pk, and file_uploads. Policy in the contributing doc is that the suite must pass at all times and that new tests use Django's own test infrastructure.
- GIS-related tests depend on native libraries. tox passenv forwards GDAL_LIBRARY_PATH, GEOS_LIBRARY_PATH, and SPATIALITE_LIBRARY_PATH. The default Tests workflow jobs read above do not install those libraries, so a green SQLite run is not evidence that django.contrib.gis was exercised.
- django.test.client exposes Client, AsyncClient, RequestFactory, and AsyncRequestFactory. They build WSGIRequest or ASGIRequest and drive BaseHandler, and FakePayload refuses seeks so views cannot read the body differently than on a real socket.
- scripts/ has its own unittest discovery (CI job scripts-tests), including scripts/pr_quality tests. That job does not install the Django test requirements file used by runtests.py.