django-tdd

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

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill django-tdd-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: django-tdd
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/django-tdd
Command: npx skills add https://github.com/Femad-6/my-skills --skill django-tdd-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable tests for Django applications requires coordinating pytest configuration, database fixtures, factories, mocking, and API testing, which is time-consuming to set up correctly from scratch. ## Core Features & Use Cases - TDD Workflow Guidance: Provides the red-green-refactor cycle with concrete Django examples for models, views, and serializers. - Testing Infrastructure Setup: Includes pytest.ini configuration, test settings, conftest.py fixtures, and factory_boy factories for rapid test data creation. - DRF API Testing: Covers serializer validation tests, ViewSet endpoint tests, authentication handling, filtering, and search testing. - Use Case: When building a new Django REST Framework endpoint, use this Skill to generate the failing test first, create factories for test data, mock external services like Stripe, and verify coverage targets. ## Quick Start Ask the AI to write pytest tests for a Django model or DRF API endpoint using factory_boy factories and the TDD workflow.

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_api_client fixture using force_authenticate, then assert on response status codes and response.data for list, retrieve, create, update, and delete operations.

How to use factory_boy with Django models for test data?

Define DjangoModelFactory subclasses with Faker and fuzzy attributes for realistic data. Use SubFactory for foreign keys, post_generation hooks for many-to-many relations, and create_batch to generate multiple objects at once.

How do I speed up Django test suites with pytest?

Use --reuse-db and --nomigrations flags, switch to MD5PasswordHasher in test settings, use an in-memory SQLite database, and disable migrations with a custom MIGRATION_MODULES class. These changes significantly reduce test run time.

Can I mock external services like Stripe in Django tests?

Yes, use unittest.mock.patch to replace external service modules at their import path. Configure return_value for success cases and side_effect for failures, then assert the mock was called with expected arguments.

What test coverage should Django projects target?

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