django-tdd

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

Updated May 7, 2026
One-click install
npx skills add https://github.com/mirzadham/trainingroombookingsystem2 --skill django-tdd-mirzadham
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: django-tdd
Source: https://github.com/mirzadham/trainingroombookingsystem2/tree/main/.pi/skills/django-tdd
Command: npx skills add https://github.com/mirzadham/trainingroombookingsystem2 --skill django-tdd-mirzadham

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable tests for Django applications and Django REST Framework APIs is often inconsistent and slow, leading to fragile test suites, low coverage, and bugs reaching production. ## Core Features & Use Cases - TDD Workflow Guidance: Provides a red-green-refactor cycle with pytest-django configuration, test settings, and reusable conftest.py fixtures. - Factory-Based Test Data: Uses factory_boy factories to generate model instances, related objects, and batch data instead of manual object creation. - Full-Stack Test Patterns: Covers model tests, view tests, DRF serializer and ViewSet API tests, mocking of external services, email assertions, and integration flow testing. - Use Case: When building a new DRF endpoint, follow the patterns to write a failing API test first, implement the view, then verify authentication, filtering, and validation behavior with factories and an authenticated API client. ## Quick Start Write pytest tests for my Django REST Framework product API using factory_boy factories and an authenticated API client.

Frequently Asked Questions about django-tdd

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

FAQPage Schema
How do I write tests for Django REST Framework APIs with pytest?▼

Use DRF's APIClient with pytest fixtures to test endpoints. Create an authenticated client via force_authenticate, then assert on status codes and response data for list, retrieve, create, update, and delete actions.

How to use factory_boy for Django test data?▼

Define DjangoModelFactory subclasses with Faker and fuzzy attributes for each model. Use SubFactory for relations, post_generation hooks for many-to-many fields, and create_batch to generate multiple objects in one call.

How do I speed up Django test runs with pytest?▼

Use --reuse-db and --nomigrations flags, an in-memory SQLite database, MD5 password hashing, and disabled migrations in test settings. These changes significantly reduce database setup time per run.

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

Use unittest.mock.patch targeting the module path where the service is imported, such as apps.payments.services.stripe. Configure return values or side effects to simulate success and failure without real network calls.

How do I test email sending in Django without sending real emails?▼

Override EMAIL_BACKEND with the locmem backend using override_settings, then inspect django.core.mail.outbox. Assert on recipient lists, subjects, and message counts after triggering the email logic.

What test coverage should a Django project target?▼

A common target is 80% overall, with 90% for models and services, 85% for serializers, and 80% for views. Generate reports with pytest --cov and review term-missing output to find untested lines.