Loading...
Loading...
pytest-django testing patterns, Factory Boy, fixtures, and TDD workflow. Use when writing tests, creating test factories, or following TDD red-green-refactor cycle.
npx skill4agent add kjnez/claude-code-django pytest-django-patterns@pytest.mark.django_dbpytestmark = pytest.mark.django_dbUserFactory()factory.Sequence()factory.Faker()factory.SubFactory()@factory.post_generationclientauth_clientclient.force_login(user)conftest.pytests/
├── apps/
│ └── posts/
│ ├── test_models.py
│ ├── test_views.py
│ └── test_forms.py
├── factories.py
└── conftest.pyTestComponentNameTestPostListViewtest_<action>_<expected_outcome>@pytest.mark.parametrizeHTTP_HX_REQUEST__str__HX-RequestHTTP_HX_REQUEST="true"response.templatesselect_related()prefetch_related()form = MyForm(data=new_data, instance=existing_obj)form.save()@pytest.mark.parametrize("input,expected", [...])mocker.patch()Model.objects.filter(...).exists()Model.objects.count() == expectedrefresh_from_db()uv run pytest # All tests
uv run pytest -x # Stop on first failure
uv run pytest --lf # Run last failed
uv run pytest -x --lf # Stop first, last failed only
uv run pytest -k "test_name" # Run tests matching pattern
uv run pytest tests/apps/posts/ # Specific directory
uv run pytest --cov=apps # With coverage report@pytest.mark.django_dbpyproject.toml[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "config.settings.test"
python_files = ["test_*.py"]
addopts = ["--reuse-db", "-ra"]conftest.py