Skip to content
Back to skills

Python Testing

ASecurity

Guide for testing Python backend services.

  • 2 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added June 5, 2026
testingpythontestingapidatabasebackend

Works with

  • api

Security analysis

A100/100

Scanned June 5, 2026

npx -y skills add Burburton/amazingteam --skill python-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Python Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/burburton-python-testing/badge)](https://www.skillsdirectory.com/skills/burburton-python-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Python Testing Skill

## Purpose

Guide for testing Python backend services.

## Testing Stack

- **pytest**: Test framework
- **pytest-asyncio**: Async test support
- **pytest-cov**: Coverage reporting
- **faker**: Test data generation
- **freezegun**: Time manipulation

## Test Structure

```
tests/
├── unit/
│   ├── test_services/
│   └── test_models/
├── integration/
│   ├── test_api/
│   └── test_database/
└── conftest.py
```

## Writing Tests

### Basic Test

```python
def test_create_user():
    user = User(name="test", email="test@example.com")
    assert user.name == "test"
    assert user.is_valid()
```

### Async Test

```python
@pytest.mark.asyncio
async def test_async_operation():
    result = await async_function()
    assert result is not None
```

### Fixture Usage

```python
@pytest.fixture
def mock_database():
    return MockDatabase()

def test_with_mock(mock_database):
    repo = UserRepository(mock_database)
    assert repo.find(1) is not None
```

## Coverage Requirements

- Minimum coverage: 80%
- Critical paths: 100%
- Run: `pytest --cov=src --cov-report=html`

## Common Patterns

### Mocking External Services

```python
from unittest.mock import patch, AsyncMock

@patch("module.external_api")
async def test_api_call(mock_api):
    mock_api.return_value = AsyncMock(return_value={"status": "ok"})
    result = await call_api()
    assert result["status"] == "ok"
```

### Database Testing

```python
@pytest.fixture
async def db_session():
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.create_all)
    yield session
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.drop_all)
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.