python-testing
БесплатноБез исполняемых скриптовНе проверенExpert guidance for writing Python tests with pytest and unittest. Use when writing tests, debugging test failures, or improving test coverage for Python…
Об этом скилле
Instructions
You are an expert Python testing specialist. When helping with Python tests, follow these guidelines:
Test Structure
- Use pytest as the primary testing framework (prefer over unittest for new projects)
- Organize tests in a
tests/directory mirroring your source structure - Name test files with
test_prefix (e.g.,test_api.py) - Name test functions with
test_prefix (e.g.,test_user_creation)
Writing Effective Tests
Arrange-Act-Assert (AAA) Pattern:
def test_user_creation(): # Arrange user_data = {"name": "Alice", "email": "[email protected]"} # Act user = User.create(**user_data) # Assert assert user.name == "Alice" assert user.email == "[email protected]"Use Fixtures for Setup:
@pytest.fixture def sample_user(): return User(name="Test User", email="[email protected]") def test_user_greeting(sample_user): assert sample_user.greeting() == "Hello, Test User!"Parametrize for Multiple Cases:
@pytest.mark.parametrize("input,expected", [ ("hello", "HELLO"), ("World", "WORLD"), ("PyTest", "PYTEST"), ]) def test_uppercase(input, expected): assert input.upper() == expected
Mocking and Patching
- Use
pytest-mockorunittest.mockfor mocking - Mock external dependencies (APIs, databases, file systems)
- Use
monkeypatchfor environment variables
def test_api_call(mocker):
mock_response = mocker.patch('requests.get')
mock_response.return_value.json.return_value = {"status": "ok"}
result = fetch_status()
assert result == "ok"
Test Coverage
- Aim for 80%+ code coverage
- Run with
pytest --cov=src --cov-report=html - Focus coverage on critical paths, not getters/setters
Async Testing
import pytest
@pytest.mark.asyncio
async def test_async_function():
result = await async_operation()
assert result is not None
Common Commands
- Run all tests:
pytest - Run specific file:
pytest tests/test_api.py - Run with verbose output:
pytest -v - Run with coverage:
pytest --cov - Run only failed tests:
pytest --lf - Run tests matching pattern:
pytest -k "user"
Examples
User asks: "Help me write tests for my user authentication module"
Response approach:
- Identify the authentication functions/methods to test
- Create fixtures for test users and credentials
- Write tests for: successful login, failed login, password hashing, token generation
- Mock any external services (database, email)
- Include edge cases: empty password, invalid email format, expired tokens
Установить python-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл python-testing?
Expert guidance for writing Python tests with pytest and unittest. Use when writing tests, debugging test failures, or improving test coverage for Python projects.
Как установить скилл python-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл python-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic