From compound-engineering-feat-python
Pytest patterns for fixtures, parametrize, mocking, async testing, and factory_boy. Use when writing or reviewing Python tests, setting up test infrastructure, or debugging test failures.
npx claudepluginhub weorbitant/compound-engineering-feat-python-plugin --plugin compound-engineering-feat-pythonThis skill uses the workspace's default tool permissions.
Patterns and conventions for writing Python tests with pytest. Follow the principle of plain
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
Patterns and conventions for writing Python tests with pytest. Follow the principle of plain test functions over class-based tests, leverage fixtures for setup and teardown, and prefer integration tests over excessive mocking.
TestCase classes. Write standalone test_ functionsconftest.pyworkspace/.venv environment and poetry:
poetry run pytest| None over Optional -- Use modern union syntax in all test code# Run all tests
poetry run pytest
# Run with verbose output
poetry run pytest -v
# Run a specific file
poetry run pytest tests/test_orders.py
# Run a specific test
poetry run pytest tests/test_orders.py::test_create_order_with_valid_data
# Run tests matching a keyword
poetry run pytest -k "order and not cancel"
# Run with coverage
poetry run pytest --cov=src --cov-report=term-missing
Fixtures provide reusable test setup with automatic cleanup. Define fixtures in conftest.py
for sharing across test modules. Use fixture scopes (function, module, session) to control
lifecycle. Fixture factories return callables for parameterized object creation.
@pytest.mark.parametrize runs the same test with different inputs. Combine multiple parameter
sets, use indirect to pass parameters through fixtures, and use pytest.param with id for
readable test IDs.
Use pytest-mock's mocker fixture over raw unittest.mock.patch. Patch at the import site,
not the definition site. Prefer spec=True for type-safe mocks. Use side_effect for
conditional returns or exceptions.
Use pytest-asyncio with asyncio_mode = "auto" in pyproject.toml to avoid decorating every
async test. Use @pytest_asyncio.fixture for async fixtures. Test FastAPI with
httpx.AsyncClient and ASGITransport.
Use factory_boy with DjangoModelFactory for test data generation. Define SubFactory for
related models, LazyAttribute for computed fields, and Trait for common variations.