django-test-performance
Improve slow Django test suites through measured profiling, safe test settings, database and migration tuning, parallel execution, test-data cleanup, and CI workflow changes. Use when Django or pytest-django tests are slow, CI test jobs take too long, database setup dominates runtime, or a user asks for a prioritized speedup plan rather than isolated test fixes.
- License 许可
- MIT
- 最近更新
- 2026-06-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- django-test-performance
- license
- MIT
- metadata
- { "tags": "django,testing,performance,pytest,ci", "version": "0.1.0", "category": "Django", "displayName": "Django Test Performance" }
- description
- Improve slow Django test suites through measured profiling, safe test settings, database and migration tuning, parallel execution, test-data cleanup, and CI workflow changes. Use when Django or pytest-django tests are slow, CI test jobs take too long, database setup dominates runtime, or a user asks for a prioritized speedup plan rather than isolated test fixes.
- compatibility
- Codex, Claude Code, and other Agent Skills-compatible clients.
02 资源文件 1
- 参考文档references/speed-wins.md2.2 KB
03 SKILL.md 正文
Django Test Performance
Use this as the orchestration skill for speeding up a Django test suite. Do not start by changing settings blindly; first measure the suite and then pick the smallest safe optimization with a repeatable verification command.
Core Workflow
-
Establish a baseline.
- Run the same command developers or CI use.
- Capture wall-clock time, runner, settings module, database backend, worker count, and branch.
- If the cause is unclear, use
django-test-profilingbefore changing behavior.
-
Classify the dominant cost.
- Startup/import/discovery: reduce collection scope and expensive app initialization.
- Database creation/migrations: reuse DB locally, squash migration history, or improve database storage.
- Per-test setup: reduce fixture data, use factories, and use
setUpTestData. - External backends: replace file storage, cache, task queues, and instrumentation with test-safe backends.
- Long tail of tests: parallelize after isolation checks.
-
Apply low-risk wins first.
- Fast password hasher.
DEBUG = Falsein tests.- Disable database serialization when serialized rollback is not needed.
- Disable debug toolbar, Sentry/Rollbar/APM initialization, and other instrumentation.
- In-memory or local test backends for storage, cache, and task queues.
- See speed-wins.md.
-
Improve data and structure.
- Use
django-test-datafor factory, fixture,setUpTestData,TestCase, and integration-vs-unit decisions.
- Use
-
Improve migrations and database setup.
- Use
--keepdbor--reuse-dbfor local repeat runs. - Force rebuilds when migration history changes.
- Prefer squashing migrations over disabling migrations globally.
- Keep the test database backend close to production unless the project is database-agnostic.
- Use
-
Parallelize only when safe.
- Use
django-test-parallelizationfor order isolation, shared resources, and worker configuration.
- Use
-
Re-measure with the original baseline command.
- Report before/after runtime and the changed risk surface.
- Keep or revert each optimization based on measured impact and behavioral fidelity.
Default Commands
time python manage.py test
python manage.py test --timing
python manage.py test --keepdb
time pytest
pytest --durations 20
pytest --reuse-db
pytest --create-db
Decision Rules
- If you cannot name the bottleneck, profile first.
- If a setting changes production-like behavior, keep the override narrow and document why tests remain representative.
- Avoid broad
TESTING = Truebranches in application code; use explicit settings and test helpers. - Do not swap PostgreSQL/MySQL/MariaDB projects to SQLite just for speed unless production is SQLite or the project intentionally supports many backends.
- Do not disable migrations as the normal path. If a legacy project insists, run real migrations in CI.
- Keep local speed shortcuts from hiding CI coverage. CI should run slow tests and migration-realistic paths somewhere.
Handoff Map
| Situation | Use |
|---|---|
| Need timings, slow-test lists, flame graphs, or cProfile output | django-test-profiling |
Enabling --parallel, pytest-xdist, or debugging random failures |
django-test-parallelization |
Fixture bloat, factories, setUpTestData, TestCase class choices |
django-test-data |
| Mocking settings, HTTP, time, output, or command input safely | django-targeted-mocking |
| CI cache, split jobs, slow markers, runner scale | django-ci-test-optimization |
Verification
Before finishing, provide:
- Baseline and final runtime from the same command.
- A ranked list of changes made or recommended.
- Risks introduced by each test-only override.
- Commands the project should keep for local and CI verification.
04 同仓库更多 Skills
android-emulator-qa
Use when validating Android feature flows in an emulator with adb-driven launch, input, UI-tree inspection, screenshots, and logcat capture.
supabase-postgres-best-practices
Postgres performance optimization and best practices from Supabase. Use this skill when writing, reviewing, or optimizing Postgres queries, schema designs, or database configurations.
sentry
Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.
render-workflows
Sets up, develops, tests, and deploys Render Workflows. Covers first-time scaffolding (via CLI or manual), SDK installation (Python or TypeScript), task patterns (retries, subtasks, fan-out), local development, Dashboard deployment, and troubleshooting. Use when a user wants to set up Render Workflows for the first time, scaffold a workflow service, add or modify workflow tasks, test workflows locally, or deploy workflows to Render.
render-web-services
Configures Render web services—port binding, TLS, health checks, custom domains, auto-deploy, PR previews, persistent disks, and deploy lifecycle. Use when the user needs to set up a web service, fix health check failures, add a custom domain, configure zero-downtime deploys, or troubleshoot port binding issues.
render-static-sites
Deploys and configures static sites on Render's global CDN—build commands, publish paths, SPA routing, redirects, custom headers, and PR previews. Use when the user needs to deploy a static site, set up a React/Vue/Hugo/Gatsby frontend, configure SPA fallback routing, add redirect rules, customize response headers, or choose between a static site and a web service for their frontend. Trigger terms: static site, CDN, SPA, single-page app, React deploy, Vue deploy, Hugo, Gatsby, Docusaurus, Jekyll, staticPublishPath.