Command Palette

Search for a command to run...

Назад к скиллам
скилл № 97752

pytest-best-practices

Expert guidance for writing high-quality pytest tests. Use when writing tests, setting up fixtures, parametrizing, mocking, or reviewing test code.

БесплатноБез исполняемых скриптов
cfircooот cfircoo★ 17 звёзд на GitHub20 установок в других каталогах

Установить pytest-best-practices в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Provide pytest best practices and patterns for writing maintainable, efficient tests. <essential_principles>

Test Independence

  • Each test must run in isolation - no shared state between tests
  • Use fixtures for setup/teardown, never class-level mutable state
  • Tests should pass regardless of execution order

Naming Conventions

  • Files: test_*.py or *_test.py
  • Functions: test_<description>()
  • Classes: Test<ClassName>
  • Fixtures: descriptive lowercase_with_underscores

Directory Structure

tests/
├── conftest.py          # Shared fixtures
├── unit/
│   └── test_module.py
├── integration/
│   └── test_api.py
└── fixtures/            # Test data files

Core Testing Rules

  • Use plain assert statements (pytest provides detailed failure messages)
  • One logical assertion per test when practical
  • Test edge cases: empty inputs, boundaries, invalid data, errors
  • Keep tests focused and readable
</essential_principles><quick_reference>
Pattern Use Case
@pytest.fixture Setup/teardown, dependency injection
@pytest.mark.parametrize Run test with multiple inputs
@pytest.mark.skip Skip test temporarily
@pytest.mark.xfail Expected failure (known bug)
pytest.raises(Exception) Test exception raising
pytest.approx(value) Float comparison
mocker.patch() Mock dependencies
conftest.py Share fixtures across modules

Common Commands

pytest -v                    # Verbose
pytest -x                    # Stop on first failure
pytest --lf                  # Run last failed
pytest -k "pattern"          # Match test names
pytest -m "marker"           # Run marked tests
pytest --cov=src             # Coverage report
</quick_reference>

Based on what you're doing, read the relevant reference:

Task Reference
Setting up fixtures, scopes, factories references/fixtures.md
Parametrizing tests, multiple inputs references/parametrization.md
Mocking, patching, faking dependencies references/mocking.md
Markers, exceptions, assertions, async references/patterns.md
```bash pip install pytest pytest-asyncio pytest-mock pytest-cov pytest-xdist ```

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • references/fixtures.md
  • references/mocking.md
  • references/parametrization.md
  • references/patterns.md

FAQ

Что делает скилл pytest-best-practices?

Expert guidance for writing high-quality pytest tests. Use when writing tests, setting up fixtures, parametrizing, mocking, or reviewing test code.

Как установить скилл pytest-best-practices?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл pytest-best-practices запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить pytest-best-practices с