dj-pytest

Configure pytest testing patterns for layered op-django projects.

109|6|Updated Apr 4, 2026
One-click install
npx skills add https://github.com/dvf/opinionated-django --skill dj-pytest
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dj-pytest
Source: https://github.com/dvf/opinionated-django/tree/main/skills/dj-pytest
Command: npx skills add https://github.com/dvf/opinionated-django --skill dj-pytest

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates the guesswork and inconsistency of setting up pytest test suites for op-django projects, which use a strict layered architecture with clear boundaries between API, service, repository, and model layers.

Core Features & Use Cases

  • Three-Layer Test Convention: Enforces separate test files for repositories (real DB, slow), services (mocked repos, fast), and APIs (HTTP integration, slow) to keep test suites fast and maintainable.
  • Prebuilt Fixtures & Configuration: Includes ready-to-use conftest fixtures for DTOs, svcs service overrides, and mock repositories, plus complete pytest configuration for django, Celery eager mode, and freezegun.
  • Use Case: Use this Skill when setting up test infrastructure for a new op-django project, writing tests for a new feature across all layers, or ensuring reliable-signal receiver tests have proper idempotency checks.

Quick Start

Use the dj-pytest skill to configure pytest for your op-django project and write a passing service test for a new business logic feature with mocked repository dependencies.

Frequently Asked Questions about dj-pytest

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

FAQPage Schema
How do I configure pytest for a layered Django project?

Configure pytest for layered Django projects by enforcing separate test files for repository, service, and API layers. This approach uses prebuilt conftest fixtures and pytest-django configuration to maintain strict boundaries and keep test suites fast and maintainable.

What's the best way to test Celery signal receivers in Django?

Testing Celery signal receivers in Django requires idempotency checks for at-least-once signal delivery. You can configure Celery eager mode alongside freezegun to reliably verify that signal receivers execute correctly without duplicate side effects.

How do I write service tests in Django without hitting the database?

Write service tests in Django without hitting the database by mocking repository dependencies with prebuilt conftest fixtures. This isolates business logic validation from the database layer, ensuring service tests run instantly and remain completely fast.

Does pytest-django work with freezegun for time-dependent tests?

Yes, pytest-django works with freezegun for time-dependent tests. The test infrastructure setup includes complete pytest configuration that integrates freezegun and Celery eager mode to reliably freeze time during signal receiver and service testing.

Why separate repository and service tests in a Django architecture?

Separating repository and service tests in a Django architecture enforces strict layer boundaries. Repository tests run slowly against a real database, while service tests mock repos to run fast, ensuring test suites remain maintainable and accurately reflect architectural dependencies.

How do I override Django service dependencies in pytest fixtures?

Override Django service dependencies in pytest fixtures using shared conftest configurations for service overrides. This provides standardized mock repositories and DTOs, allowing you to isolate and test specific service behaviors without triggering downstream database operations.