django-tdd

A testing guide for Django applications using pytest-django, factory_boy, mocks, coverage reports, and Django REST Framework APIs. TDD means writing a failing test first, making it pass, and then improving the implementation.

In plain words
What is it for?
Use it when creating Django apps, building REST APIs, testing database models or request handlers, setting up test infrastructure, or following a TDD workflow.
Why use it?
It provides a consistent way to test models, views, serializers, and APIs instead of relying on manual checks. The setup also helps track untested code and keep test databases manageable.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/luohaothu/everything-codex/django-tdd
Any agent
npx skills add Luohaothu/everything-codex --skill django-tdd
Clone the repo
git clone --depth 1 https://github.com/Luohaothu/everything-codex

Made for: Claude Code, Codex.

Per session 34 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,635 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00034 $0.04635
Opus 5 $0.00017 $0.02318
Sonnet 5 $0.00007 $0.00927
Haiku 4.5 $0.00003 $0.00464

Measured 2d ago against content hash a17f87efa64c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

django-tdd scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/zh-CN/skills/django-tdd/SKILL.md · 729 lines

How it starts

The opening of the file, as written. The whole thing — 729 lines — stays where its author put it; the contents beside it link to each section on GitHub.

使用 TDD 进行 Django 测试

使用 pytest、factory_boy 和 Django REST Framework 进行 Django 应用程序的测试驱动开发。

何时激活

  • 编写新的 Django 应用程序时
  • 实现 Django REST Framework API 时
  • 测试 Django 模型、视图和序列化器时
  • 为 Django 项目设置测试基础设施时

Django 的 TDD 工作流

红-绿-重构循环

# Step 1: RED - Write failing test
def test_user_creation():
    user = User.objects.create_user(email='[email protected]', password='testpass123')
    assert user.email == '[email protected]'
    assert user.check_password('testpass123')
    assert not user.is_staff

# Step 2: GREEN - Make test pass
# Create User model or factory

# Step 3: REFACTOR - Improve while keeping tests green

设置

pytest 配置

# pytest.ini
[pytest]
DJANGO_SETTINGS_MODULE = config.settings.test
testpaths = tests
python_files = test_*.py
python_classes = Test*
python_functions = test_*
addopts =
    --reuse-db
    --nomigrations
    --cov=apps
    --cov-report=html
    --cov-report=term-missing
    --strict-markers
markers =
    slow: marks tests as slow
    integration: marks tests as integration tests

测试设置

# config/settings/test.py
from .base import *

DEBUG = True
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': ':memory:',
    }
}

# Disable migrations for speed
class DisableMigrations:
    def __contains__(self, item):
        return True

    def __getitem__(self, item):
        return None

MIGRATION_MODULES = DisableMigrations()

# Faster password hashing
PASSWORD_HASHERS = [
    'django.contrib.auth.hashers.MD5PasswordHasher',
]

# Email backend
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# Celery always eager
CELERY_TASK_ALWAYS_EAGER = True
CELERY_TASK_EAGER_PROPAGATES = True

conftest.py

# tests/conftest.py
import pytest
from django.utils import timezone
from django.contrib.auth import get_user_model

User = get_user_model()

@pytest.fixture(autouse=True)
def timezone_settings(settings):
    """Ensure consistent timezone."""
    settings.TIME_ZONE = 'UTC'

@pytest.fixture
def user(db):
    """Create a test user."""
    return User.objects.create_user(
        email='[email protected]',
        password='testpass123',
        username='testuser'
    )

@pytest.fixture
def admin_user(db):
    """Create an admin user."""
    return User.objects.create_superuser(
        email='[email protected]',
        password='adminpass123',
        username='admin'
    )

@pytest.fixture
def authenticated_client(client, user):
    """Return authenticated client."""
    client.force_login(user)
    return client

@pytest.fixture
def api_client():
    """Return DRF API client."""
    from rest_framework.test import APIClient
    return APIClient()

@pytest.fixture
def authenticated_api_client(api_client, user):
    """Return authenticated API client."""
    api_client.force_authenticate(user=user)
    return api_client

Read the full file on GitHub · 729 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 729 lines · 34 tokens per session scan A a17f87efa64c

Subscribe to this mod's changes

django-tdd is a skill published in the GitHub repository Luohaothu/everything-codex (24 stars, last pushed 22d ago), licensed MIT. It adds 34 tokens to every session and 4,635 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

python-tdd-with-uv

Test-driven development in Python using uv as the package manager. Covers the red-green-refactor cycle, vertical slicing, and uv project setup.

spencerpauly/awesome-cursor-skills · 35 tokens

tdd

Strict Python TDD workflow using pytest (Red-Green-Refactor).

MODSetter/SurfSense · 18 tokens

lettuce-skill

Generates Lettuce BDD tests for Python with feature files and step definitions. Note: Lettuce is legacy/unmaintained; consider Behave for new projects. Use when user specifically mentions "Lettuce". Triggers on: "Lettuce", "lettuce test", "lettuce BDD".

LambdaTest/agent-skills · 68 tokens

python-tdd

Python development with TDD using pytest, type checking with mypy, and linting with ruff/black. Use when working on Python projects requiring test-driven development, quality gates, or Python code review. Do NOT use for other programming languages.

randomm/pi-ensemble · 54 tokens

wu5-dev-flow

使用可审计的 SDD、严格 RED-GREEN-REFACTOR TDD 与安全 Git 门禁初始化、开发、修复、重构和交付 Python 项目。用于任何会修改项目源码、测试、规格、依赖或 Git 历史的任务,也用于继续跨 Session 的现有 spec/ 变更、审查代码、验证完成状态、创建提交或准备 GitHub PR。.

WenOwen/wu5-dev-flow · 94 tokens

python-conventions

Team-specific Python conventions — credential management with dotenv, API client rules, LLM response parsing, TDD workflow, and testing patterns for data pipelines.

Benkapner/claude-code-basecamp · 34 tokens