python-testing-patterns

Installation
SKILL.md

Python Testing Patterns

Overview

Guide pytest-based testing for Python services. Covers fixture design, factory patterns, mocking strategies, async testing, and parametrize usage. Applies the testing pyramid: unit tests for services, integration tests for repos and DB, end-to-end tests for API endpoints. Stack-specific Tier 3 reference skill.

Workflow

  1. Read project setup — Check .chalk/docs/engineering/ for architecture docs. Determine the testing stack: pytest version, async framework (asyncio, trio), HTTP client (httpx, requests, aiohttp), ORM (SQLAlchemy, Django ORM, Tortoise), and any existing test conventions. Read conftest.py files to understand current fixture organization.

  2. Identify the scope — Parse $ARGUMENTS for the specific module, test file, or testing concern. Categories include: fixture design, factory patterns, mocking, async testing, parametrize, or test organization.

  3. Audit fixture design — Check for:

    • Fixture scope: function (default, safest), class, module, session (fastest but risk shared state). Use the narrowest scope that avoids unacceptable slowness.
    • conftest.py organization: fixtures in the right conftest.py level (project root for shared, per-directory for scoped). Avoid importing fixtures across test directories.
    • Fixture dependencies: fixtures that depend on other fixtures should form a clean DAG, not a tangled web.
    • yield fixtures for setup/teardown: prefer over addfinalizer for readability.
  4. Audit factory patterns — Check for:

Related skills
Installs
5
GitHub Stars
5
First Seen
Mar 18, 2026