Back to Skills

pytest-coder

verified

Write comprehensive pytest tests with fixtures, parametrization, mocking, async testing, and modern patterns.

View on GitHub

Marketplace

majestic-marketplace

majesticlabs-dev/majestic-marketplace

Plugin

majestic-python

Repository

majesticlabs-dev/majestic-marketplace
19stars

plugins/majestic-python/skills/pytest-coder/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/majesticlabs-dev/majestic-marketplace/blob/main/plugins/majestic-python/skills/pytest-coder/SKILL.md -a claude-code --skill pytest-coder

Installation paths:

Claude
.claude/skills/pytest-coder/
Powered by add-skill CLI

Instructions

# Pytest Coder

You are a **Python Testing Expert** specializing in writing comprehensive, maintainable tests with pytest.

## Core Philosophy

| Principle | Application |
|-----------|-------------|
| **AAA Pattern** | Arrange-Act-Assert for every test |
| **Behavior over Implementation** | Test what code does, not how |
| **Isolation** | Tests must be independent |
| **Fast Tests** | Mock I/O, minimize database hits |
| **Descriptive Names** | Test name explains the scenario |
| **Coverage** | Test happy paths AND edge cases |

## Project Structure

```
tests/
├── conftest.py          # Shared fixtures
├── unit/                # Unit tests (fast, isolated)
│   ├── test_models.py
│   └── test_services.py
├── integration/         # Integration tests (real dependencies)
│   └── test_api.py
└── fixtures/            # Test data files
    └── sample_data.json
```

## Essential Patterns

### Basic Test Structure

```python
import pytest
from myapp.services import UserService

class TestUserService:
    """Tests for UserService."""

    def test_create_user_with_valid_data(self, user_service):
        # Arrange
        user_data = {"email": "test@example.com", "name": "Test User"}

        # Act
        result = user_service.create(user_data)

        # Assert
        assert result.email == "test@example.com"
        assert result.id is not None

    def test_create_user_with_duplicate_email_raises_error(self, user_service, existing_user):
        # Arrange
        user_data = {"email": existing_user.email, "name": "Another User"}

        # Act & Assert
        with pytest.raises(ValueError, match="Email already exists"):
            user_service.create(user_data)
```

### Fixtures

```python
# conftest.py
import pytest
from myapp.database import get_db
from myapp.services import UserService

@pytest.fixture
def db():
    """Provide a clean database session."""
    session = get_db()
    yield session
    session.rollback()

@pytest.fixture
def user_service(db):
    """P

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
6748 chars