Django Test Data
SkillFiles & storageDesign faster, clearer Django test data and test structure with factories, setUpTestData, SimpleTestCase/TestCase choices, fixture-file cleanup, query optimization, and unit-vs-integration boundaries. Use when Django tests create too much data, rely on slow fixtures, overuse TransactionTestCase, duplicate setup, or need refactoring for speed without losing coverage.
Use Django Test Data in Claude, ChatGPT or Ahel Desktop
Free. Sign in, add Django Test Data and connect your AI. About a minute.
Also: Claude Code · Cursor · Codex
Then ask your AI: use the Django Test Data skill
Details
Instructions available. Your AI can read the instructions. Execution depends on the setup they require.
Account requirements not reviewed. Check the skill instructions before use; ahel provides instructions and does not run this skill.
No other account needed.
Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.
What this skill tells your AI
The instructions your AI receives, as published by hashgraph-online/awesome-codex-plugins in plugins/LVTD-LLC/skills/skills/django-test-data/SKILL.md and read by ahel’s review.
Most slow Django suites spend time building data they do not need or exercising full request/database paths for behavior that can be tested at a smaller boundary. Use this skill to reduce setup cost while keeping representative integration coverage.
Refactoring Workflow
-
Map the behavior under test.
- Identify the smallest useful boundary: function, form, model method, middleware, command helper, view, or full request path.
- Keep a few integration tests for wiring; move detailed cases to unit tests where the boundary is clean.
-
Choose the fastest test base class.
SimpleTestCase: no database access.TestCase: ordinary database tests with rollback.TransactionTestCase: committed transaction behavior only.LiveServerTestCase: browser/live-server tests only.
-
Remove broad fixture data.
- Avoid large fixture files and base classes that always create objects.
- Build only the data each test or class needs.
-
Use factories deliberately.
- Start with small factory functions when the domain is simple.
- Use Factory Boy or Model Bakery when relationships and variants become repetitive.
-
Share class-level data with
setUpTestData.- Use
setUpTestData()for database objects reused by multiple methods in aTestCase. - Avoid mutating shared in-memory objects across methods.
- Use
-
Optimize database access in test setup and assertions.
- Use
select_related,prefetch_related, orbulk_createwhere setup/query cost is the bottleneck. - Assert query counts for hot paths when performance is part of the contract.
- Use
Read patterns.md for examples and decision details.
Decision Rules
- If a test does not need the database, use
SimpleTestCase. - If only some tests need the database, split them into separate classes.
- If a test requires committed transaction behavior, first check whether
captureOnCommitCallbacks()or an inneratomic()is enough. - If many tests share expensive objects, use
setUpTestDatainstead ofsetUp. - If fixture files are hard to understand or grow over time, replace them with factories.
- If a test depends on hard-coded auto-increment IDs, fix the assertion rather than enabling
reset_sequences=True. - Combine assertions when they describe one behavior produced by one expensive action.
Common Mistakes
- Testing form validation only through rendered HTML instead of inspecting form errors directly.
- Leaving management-command business logic inside
handle(), forcing tests throughcall_command(). - Using
TransactionTestCaseas the default. - Putting data in a base
TestCasethat only a few subclasses need. - Treating factories as permission to create a large object graph for every test.
- Mutating objects created by
setUpTestDataand leaking in-memory state to later tests.
Verification
Before finishing a refactor:
- The old behavior remains covered at the right level.
- Database-using and non-database tests are split where useful.
- Repeated setup moved to
setUpTestDataor factories only where it reduces cost. - Relevant tests pass individually and as part of their module/class.
Signals
- GitHub stars
- 1k
- Forks
- 316
- Last commit
- Oct 2026
Advanced
- Item type
- skill
- Key
django-test-data- Source
- github.com/hashgraph-online/awesome-codex-plugins
github.com/hashgraph-online/awesome-codex-plugins
Related picks
Skill · hashgraph-online
The pick for Djangointegration-django
Skill · posthog
The pick for Djangopython-performance-optimization
Skill · wshobson
The pick for Pythonpython-pro
Skill · jeffallan
The pick for Pythonpptx
Skill · anthropics
More in Files & storagedocx
Skill · anthropics
More in Files & storage