django-tdd

Set up pytest-django, factory_boy, and DRF testing for Django applications.

1|Updated Mar 20, 2024
One-click install
npx skills add https://github.com/flag3/dotfiles --skill django-tdd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: django-tdd
Source: https://github.com/flag3/dotfiles/tree/main/.claude/skills/django-tdd
Command: npx skills add https://github.com/flag3/dotfiles --skill django-tdd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Django-tdd addresses the challenge of ensuring correct behavior in Django applications by enabling thorough, repeatable testing with pytest-django, factory_boy, and Django REST Framework.

Core Features & Use Cases

  • Structured TDD workflow: write failing tests, implement minimal code to pass, refactor while keeping tests green.
  • Fixtures & factories: leverage factory_boy for consistent, scalable test data across models and API endpoints.
  • DRF API testing: verify serializers, views, and endpoints with unit and integration tests to ensure API reliability.
  • Real-world scenarios: validate new Django apps, models, views, and serializers in a fast feedback loop.

Quick Start

Set up a new Django project and run pytest to exercise the TDD workflow. Install dependencies, write a failing test for a model or API, implement the minimal code to pass, and iterate until the tests are green.

Frequently Asked Questions about django-tdd

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

FAQPage Schema
How do I write reliable tests for Django REST Framework APIs?

Test-driven development with pytest-django and factory_boy enables reliable DRF API testing by writing failing tests first for serializers, views, and endpoints, then implementing minimal code to pass. This approach ensures API behavior is verified before deployment and remains correct through refactoring.

What's the best way to set up test data for Django models and API endpoints?

Factory_boy provides scalable, consistent test fixtures for Django models and API endpoints. Define factories once, reuse them across unit and integration tests to generate realistic data quickly, reducing duplication and maintenance overhead in your test suite.

Can I use pytest-django for testing Django views and serializers?

Yes. pytest-django integrates with Django's testing framework to test views, serializers, and endpoints efficiently. It works with factory_boy and standard Django project configurations to validate business logic in a fast feedback loop without requiring separate test runners.

Why is test-driven development important for Django applications?

Test-driven development ensures correct behavior in Django applications by establishing repeatable test infrastructure before writing implementation code. This workflow—write failing test, implement minimal code, refactor while tests pass—catches bugs early, documents expected behavior, and prevents regressions.

Do I need special configuration to run pytest with Django projects?

Pytest requires minimal Django setup: a pytest.ini file and configured Django settings. Once configured, pytest-django discovers and runs tests against your Django models, views, and serializers without additional tooling beyond standard Python dependencies.

What's the difference between unit and integration testing for Django REST APIs?

Unit tests verify individual serializers and views in isolation; integration tests validate complete request-response flows across endpoints. Both approaches use pytest-django and factory_boy to ensure API reliability at different levels of granularity and help identify integration issues early.