django-test-parallelization
Safely parallelize Django and pytest-django test suites with Django --parallel, pytest-xdist, test isolation checks, randomized order detection, shared-resource sharding, locks, and load balancing. Use when enabling parallel tests, diagnosing failures under parallel execution, handling flaky Django tests, or making caches, files, queues, and external resources safe across workers.
- License 许可
- MIT
- 最近更新
- 2026-06-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- django-test-parallelization
- license
- MIT
- metadata
- { "tags": "django,testing,parallelization,pytest,xdist", "version": "0.1.0", "category": "Django", "displayName": "Django Test Parallelization" }
- description
- Safely parallelize Django and pytest-django test suites with Django --parallel, pytest-xdist, test isolation checks, randomized order detection, shared-resource sharding, locks, and load balancing. Use when enabling parallel tests, diagnosing failures under parallel execution, handling flaky Django tests, or making caches, files, queues, and external resources safe across workers.
- compatibility
- Codex, Claude Code, and other Agent Skills-compatible clients.
02 资源文件 1
- 参考文档references/shared-resources.md2.2 KB
03 SKILL.md 正文
Django Test Parallelization
Parallel test execution is a multiplier after a suite is isolated. Treat failures under parallel execution as evidence of hidden shared state until proven otherwise.
Readiness Workflow
-
Measure serial runtime first.
- If the suite is already dominated by startup or database creation, parallelism may not help enough on its own.
-
Check isolation before enabling parallelism as the default.
- Run in reverse order.
- Run with randomized order when reverse order is not enough.
- Preserve random seeds so failures can be reproduced.
-
Enable the runner deliberately.
- Django runner: install
tblib, then runpython manage.py test --parallel. - pytest-django: install
pytest-xdist, then runpytest -n auto.
- Django runner: install
-
Classify failures.
- Order-dependent failures usually come from mutated globals, class attributes, settings, caches, monkeypatches, or database assumptions.
- Parallel-only failures usually come from shared resources such as files, cache keys, ports, queues, external services, or temporary directories.
-
Make resources worker-safe.
- Prefer sharding per process or worker.
- Use locks only when the resource cannot be partitioned.
- Keep lock scope narrow.
-
Balance work after it is correct.
- Split large test classes or modules only when measurement shows one group holds back the parallel run.
Commands
python -m pip install tblib
python manage.py test --parallel
python manage.py test --parallel 1
python manage.py test --reverse
python -m pip install pytest-xdist
pytest -n auto
pytest -n auto --dist loadscope
For shared-resource patterns, read shared-resources.md.
Decision Rules
- Add parallel testing early in new projects; older serial suites often have hidden isolation assumptions.
- Use CI reverse-order testing as a low-friction guard against order dependencies.
- Use random order when reverse order misses a suspected dependency, and capture the seed.
- Prefer
pytest -n auto --dist loadscopefor DjangoTestCase-heavy suites because class/module setup can be expensive. - Shard resources before reaching for locks.
- Put process-specific behavior in test settings only, not production settings.
- Split large test groups only after profiling shows an imbalance.
Common Mistakes
- Assuming database transaction isolation protects caches, files, task queues, or external systems.
- Mutating class attributes, globals, app settings, or cache entries without restoring them.
- Enabling random order without preserving the seed.
- Using a single lockfile for too much work and accidentally serializing the suite.
- Letting pytest-xdist split related tests so finely that setup cost is duplicated.
- Making parallelism the default before the suite passes reliably under order-isolation checks.
Verification
Before calling parallelization complete:
- Serial run passes.
- Reverse or random-order run passes, or known failures are fixed.
- Parallel run passes at least twice.
- Any shared-resource sharding lives in test configuration.
- CI has a serial fallback command for debugging.
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.