pytest

Enforce pytest best practices for Django tests with fixtures and mocking.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/felipe3dfx/dotfiles --skill pytest-felipe3dfx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest
Source: https://github.com/felipe3dfx/dotfiles/tree/main/skills/pytest
Command: npx skills add https://github.com/felipe3dfx/dotfiles --skill pytest-felipe3dfx

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides best practices and patterns for writing robust, maintainable, and efficient Python tests using pytest, reducing common pitfalls and improving code quality.

Core Features & Use Cases

  • Standardized Test Structure: Enforces consistent patterns for test functions, avoiding class-based tests and module-level docstrings.
  • Mocking Best Practices: Guides users to leverage pytest-mock's mocker fixture over unittest.mock and prioritize HTTP-layer mocking.
  • Factory and Fixture Patterns: Demonstrates effective use of Factory Boy for test data generation and fixture composition for complex setups.
  • Use Case: When developing a new Django feature, use this Skill to ensure all associated tests follow established patterns for views, services, and data setup, leading to a more reliable codebase.

Quick Start

Use the pytest skill to write a new test for a Django view that requires authentication.

Frequently Asked Questions about pytest

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

FAQPage Schema
How do I write pytest tests for Django views that require authentication?

Writing pytest tests for Django views relies on standalone functions, Factory Boy for data generation, and fixture composition to handle authentication reliably while avoiding class-based test structures.

What is the best way to mock external services in Python tests?

Mocking external services in Python tests is best handled at the HTTP layer using the `pytest-mock` mocker fixture, which ensures test reliability and maintainability over direct `unittest.mock` usage.

Does pytest work with Factory Boy for test data generation?

pytest works seamlessly with Factory Boy for test data generation by enforcing specific factory patterns and fixture composition, ensuring complex data setups remain maintainable and standardized across your test suite.

Why should I use standalone functions instead of class-based tests in pytest?

Standalone functions in pytest are enforced because they avoid common testing anti-patterns found in class-based tests, reducing module-level docstrings and ensuring a standardized, maintainable test structure across your project.

Can I use unittest.mock instead of pytest-mock for mocking in Django testing?

Using `pytest-mock`'s `mocker` fixture is prioritized over `unittest.mock` for Django testing because it enforces correct mocking strategies and HTTP-layer mocking, preventing external service anti-patterns and improving test reliability.

When do I need to use fixture composition for Python testing?

Fixture composition is needed for Python testing when handling complex setups in Django projects, allowing you to combine factories and mocking patterns effectively to ensure test data generation remains robust and maintainable.