django-tdd

Implements test-driven development for Django applications using pytest, factory_boy, and DRF testing patterns.

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill django-tdd-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: django-tdd
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/django-tdd
Command: npx skills add https://github.com/ibytechaos/claude --skill django-tdd-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Django projects often lack structured testing practices, leading to fragile code, untested API endpoints, and slow feedback loops. This Skill provides a complete TDD methodology with ready-to-use configurations, fixtures, factories, and test patterns for Django and Django REST Framework. ## Core Features & Use Cases - pytest-django Setup: Provides pytest.ini configuration, test settings with in-memory SQLite, disabled migrations, and reusable conftest.py fixtures for users, clients, and authenticated API clients. - Factory-Based Test Data: Demonstrates factory_boy patterns with DjangoModelFactory, sequences, fuzzy attributes, SubFactory relations, and post-generation hooks for many-to-many fields. - Full-Stack Test Coverage: Covers model tests, view tests, DRF serializer and ViewSet API tests, mocking external services like Stripe, email testing with locmem backend, and end-to-end integration flows. - Use Case: When building a new Django REST Framework endpoint, follow the Red-Green-Refactor cycle to write failing API tests first, then implement the serializer and view until tests pass, using factories for test data. ## Quick Start Ask the AI to set up a pytest-django test suite with factories and write TDD tests for a Django model and its DRF API endpoints.

Frequently Asked Questions about django-tdd

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up pytest for a Django project?

Create a pytest.ini file with DJANGO_SETTINGS_MODULE pointing to a test settings module, then add options like --reuse-db and --nomigrations for speed. Use a dedicated test settings file with in-memory SQLite and MD5 password hashing to keep tests fast.

How to write tests for Django REST Framework APIs?

Use DRF's APIClient to make requests against your endpoints and assert on status codes and response data. Use force_authenticate to bypass authentication in tests, and reverse() to resolve URLs for ViewSet routes like product-list and product-detail.

What is factory_boy and how does it work with Django?

factory_boy generates test data through DjangoModelFactory classes that define default attributes using sequences, Faker providers, and fuzzy values. SubFactory handles foreign keys, and post_generation hooks manage many-to-many relationships like tags.

How do I mock external services like Stripe in Django tests?

Use unittest.mock.patch to replace the external module, such as apps.payments.services.stripe, then configure return values or side effects on the mock. This isolates tests from network calls and lets you simulate both successful and failed payment scenarios.

Why are my Django tests slow and how can I speed them up?

Slow tests usually come from running migrations and recreating the database each run. Use --reuse-db and --nomigrations flags, switch to MD5PasswordHasher in test settings, and use an in-memory SQLite database to significantly reduce test execution time.

What test coverage should a Django project target?

A reasonable target is 80% overall coverage, with models and services at 90% or higher, serializers at 85%, and views at 80%. Generate reports with pytest --cov=apps --cov-report=html to identify untested code paths.