django-tdd

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

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill django-tdd-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: django-tdd
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/django-tdd
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill django-tdd-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pytest, pytest-django, factory_boy, djangorestframework, faker.

What problem does it solve? Django developers often struggle to set up consistent testing infrastructure and write maintainable tests for models, views, serializers, and REST APIs. This Skill provides a complete TDD workflow with ready-to-use pytest configuration, fixtures, factories, and testing patterns. ## Core Features & Use Cases - TDD Workflow Guidance: Red-Green-Refactor cycle applied to Django models, views, and DRF API endpoints. - Testing Infrastructure Setup: pytest.ini configuration, test settings with in-memory SQLite, disabled migrations, and reusable conftest.py fixtures. - Factory Boy Patterns: Model factories with sequences, fuzzy fields, SubFactory relations, and post-generation hooks for realistic test data. - Use Case: When building a new Django REST Framework endpoint, use this Skill to write failing serializer and ViewSet tests first, mock external services like Stripe, and verify the full checkout flow with integration tests. ## Quick Start Ask the AI to set up pytest-django testing with factory_boy factories and write TDD tests for your Django models and 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 test settings, configure testpaths and python_files patterns, and add options like --reuse-db and --nomigrations for speed. Use a dedicated test settings module with in-memory SQLite and MD5 password hashing.

How to test Django REST Framework APIs with pytest?▼

Use DRF's APIClient as a fixture and call force_authenticate to bypass authentication in tests. Test list, retrieve, create, update, and delete endpoints by asserting status codes and response data against factory-generated objects.

What is factory_boy used for in Django testing?▼

factory_boy generates test data through DjangoModelFactory classes instead of manual object creation. It supports sequences for unique fields, Faker for realistic values, SubFactory for relations, and post_generation hooks for many-to-many fields 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_value for success cases or side_effect for failures. Assert the mock was called and verify the view handles both outcomes correctly.

Why are my Django tests slow and how to speed them up?▼

Slow tests usually come from running migrations and recreating the database each run. Use --reuse-db and --nomigrations flags, switch to in-memory SQLite, use MD5PasswordHasher, and set Celery to eager mode in test settings.

What should I not test in a Django application?▼

Avoid testing Django internals and third-party library code, since those are already tested upstream. Do not test private methods directly, over-mock internal logic, or make tests dependent on execution order.