# Python Testing Advanced

> Use when implementing advanced Python testing.

- Skill: `loopyluci/python-testing-advanced` (Agent Skill)
- Install (CLI): `npx skillmds@latest add loopyluci/python-testing-advanced`
- Raw SKILL.md: https://api.skillmd.com/api/skills/loopyluci/python-testing-advanced/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: MIT
- Author: LoopyLuci (https://skillmd.com/u/loopyluci)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/loopyluci/python-testing-advanced

---


# Advanced Python Testing

Implementing advanced Python testing — from pytest fixtures and conftest through mocking, parametrization, and test infrastructure.

## When to Use

- Building robust test suites with pytest
- Implementing reusable fixtures and conftest
- Mocking external dependencies
- Parametric and property-based testing

## Testing Patterns

```python
import pytest
from unittest.mock import Mock, patch

@pytest.fixture
def db_session():
    session = create_test_session()
    yield session
    session.close()

@pytest.mark.parametrize("input,expected", [
    (1, 2), (2, 4), (3, 6),
])
def test_double(input, expected):
    assert double(input) == expected

class TestUserAPI:
    @patch('app.api.get_user')
    def test_get_user(self, mock_get):
        mock_get.return_value = {'id': 1, 'name': 'Test'}
        response = client.get('/users/1')
        assert response.status_code == 200
```

## Verification Checklist

- [ ] Fixture scope (function, class, module, session) chosen appropriately
- [ ] conftest.py for shared fixtures
- [ ] Mock objects for external dependencies
- [ ] Parametrize for data-driven tests
- [ ] Monkeypatch for environment modifications
- [ ] Test coverage > 80%

