claude-desktop-skills/pytest-generator/SKILL.md
You are an expert at writing tests with pytest.
npx skillsauth add ViggyV/claude-skills Pytest GeneratorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are an expert at writing tests with pytest.
This skill activates when the user needs help with:
# tests/conftest.py - Shared fixtures
import pytest
from unittest.mock import AsyncMock
@pytest.fixture
def sample_user():
return {"id": "123", "email": "[email protected]", "name": "Test User"}
@pytest.fixture
def mock_db():
db = AsyncMock()
db.get.return_value = None
db.save.return_value = True
return db
@pytest.fixture
async def async_client(app):
async with AsyncClient(app=app, base_url="http://test") as client:
yield client
# tests/unit/test_services.py
class TestUserService:
def test_get_user_returns_user(self, mock_db, sample_user):
mock_db.get.return_value = sample_user
service = UserService(mock_db)
result = service.get("123")
assert result == sample_user
mock_db.get.assert_called_once_with("123")
def test_get_user_not_found_raises(self, mock_db):
mock_db.get.return_value = None
service = UserService(mock_db)
with pytest.raises(UserNotFoundError):
service.get("invalid")
# Scoped fixtures
@pytest.fixture(scope="session")
def database():
"""Create database once per test session."""
db = create_test_database()
yield db
db.drop()
@pytest.fixture(scope="function")
def clean_db(database):
"""Clean database between tests."""
yield database
database.clear_all()
# Factory fixtures
@pytest.fixture
def create_user(db):
def _create_user(**kwargs):
defaults = {"email": "[email protected]", "name": "Test"}
defaults.update(kwargs)
return User.create(**defaults)
return _create_user
# Usage
def test_multiple_users(create_user):
user1 = create_user(email="[email protected]")
user2 = create_user(email="[email protected]")
@pytest.mark.parametrize("input,expected", [
("hello", "HELLO"),
("world", "WORLD"),
("", ""),
("123", "123"),
])
def test_uppercase(input, expected):
assert input.upper() == expected
@pytest.mark.parametrize("value,is_valid", [
("[email protected]", True),
("invalid", False),
("", False),
("[email protected]", True),
])
def test_email_validation(value, is_valid):
assert validate_email(value) == is_valid
# Multiple parameters
@pytest.mark.parametrize("a,b,expected", [
(1, 2, 3),
(0, 0, 0),
(-1, 1, 0),
])
def test_add(a, b, expected):
assert add(a, b) == expected
from unittest.mock import Mock, patch, MagicMock
def test_external_api_call():
with patch('myapp.services.requests.get') as mock_get:
mock_get.return_value.json.return_value = {"status": "ok"}
mock_get.return_value.status_code = 200
result = fetch_data("http://api.example.com")
assert result["status"] == "ok"
mock_get.assert_called_once()
@patch('myapp.services.EmailClient')
def test_send_email(mock_email_client):
mock_instance = mock_email_client.return_value
mock_instance.send.return_value = True
result = send_notification("[email protected]", "Hello")
assert result is True
mock_instance.send.assert_called_with("[email protected]", "Hello")
# Async mocking
@pytest.mark.asyncio
async def test_async_service():
mock_repo = AsyncMock()
mock_repo.get.return_value = {"id": "123"}
service = UserService(mock_repo)
result = await service.get_user("123")
assert result["id"] == "123"
import pytest
@pytest.mark.asyncio
async def test_async_function():
result = await async_operation()
assert result == expected
@pytest.mark.asyncio
async def test_api_endpoint(async_client):
response = await async_client.get("/api/users")
assert response.status_code == 200
assert len(response.json()) > 0
# Fixture for async setup
@pytest.fixture
async def async_db():
db = await create_async_db()
yield db
await db.close()
# Mark tests
@pytest.mark.slow
def test_slow_operation():
pass
@pytest.mark.integration
def test_database_integration():
pass
@pytest.mark.skip(reason="Not implemented yet")
def test_future_feature():
pass
@pytest.mark.skipif(sys.platform == "win32", reason="Unix only")
def test_unix_feature():
pass
# Run specific marks: pytest -m "not slow"
# Group related tests
class TestUserCreation:
def test_valid_user(self):
pass
def test_invalid_email(self):
pass
def test_duplicate_email(self):
pass
[pytest]
testpaths = tests
python_files = test_*.py
python_functions = test_*
addopts = -v --tb=short --strict-markers -ra
markers =
slow: marks tests as slow
integration: integration tests
unit: unit tests
asyncio_mode = auto
filterwarnings =
ignore::DeprecationWarning
Provide:
data-ai
Use this skill for reinforcement learning tasks including training RL agents (PPO, SAC, DQN, TD3, DDPG, A2C, etc.), creating custom Gym environments, implementing callbacks for monitoring and control,
testing
You are an expert at optimizing SQL queries for performance and efficiency.
tools
Knowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a G
tools
21 production-ready scripts for iOS app testing, building, and automation. Provides semantic UI navigation, build automation, accessibility testing, and simulator lifecycle management. Optimized for A