> **Источник:** https://python-all.ru/3.7/library/development.html
>
> «Документация Python на русском» – неофициальный перевод официальной документации Python: версии от 2.6 до 3.16, полнотекстовый поиск, английский оригинал рядом с переводом. Эта Markdown-версия страницы предназначена для работы с LLM: вставьте её в ChatGPT, Claude или Cursor.

---

# Инструменты разработки

Модули, описанные в этой главе, помогают писать программное обеспечение. Например, модуль [`pydoc`](https://python-all.ru/3.7/library/pydoc.html#module-pydoc) принимает модуль и генерирует документацию на основе его содержимого. Модули [`doctest`](https://python-all.ru/3.7/library/doctest.html#module-doctest) и [`unittest`](https://python-all.ru/3.7/library/unittest.html#module-unittest) содержат фреймворки для написания модульных тестов, которые автоматически выполняют код и проверяют, что вывод соответствует ожидаемому. **2to3** может переводить исходный код Python 2.x в корректный код Python 3.x.

Список модулей, описанных в этой главе:

- [`typing` – Поддержка аннотаций типов](https://python-all.ru/3.7/library/typing.html)

  - [Псевдонимы типов](https://python-all.ru/3.7/library/typing.html#type-aliases)
  - [NewType](https://python-all.ru/3.7/library/typing.html#newtype)
  - [Callable](https://python-all.ru/3.7/library/typing.html#callable)
  - [Обобщённые типы](https://python-all.ru/3.7/library/typing.html#generics)
  - [Пользовательские обобщённые типы](https://python-all.ru/3.7/library/typing.html#user-defined-generic-types)
  - [Тип `Any`](https://python-all.ru/3.7/library/typing.html#the-any-type)
  - [Классы, функции и декораторы](https://python-all.ru/3.7/library/typing.html#classes-functions-and-decorators)
- [`pydoc` – генератор документации и система интерактивной справки](https://python-all.ru/3.7/library/pydoc.html)
- [`doctest` – тестирование интерактивных примеров Python](https://python-all.ru/3.7/library/doctest.html)

  - [Простое использование: проверка примеров в строках документации](https://python-all.ru/3.7/library/doctest.html#simple-usage-checking-examples-in-docstrings)
  - [Простое использование: проверка примеров в текстовом файле](https://python-all.ru/3.7/library/doctest.html#simple-usage-checking-examples-in-a-text-file)
  - [Как это работает](https://python-all.ru/3.7/library/doctest.html#how-it-works)

    - [Какие строки документации проверяются?](https://python-all.ru/3.7/library/doctest.html#which-docstrings-are-examined)
    - [Как распознаются примеры в строках документации?](https://python-all.ru/3.7/library/doctest.html#how-are-docstring-examples-recognized)
    - [Каков контекст выполнения?](https://python-all.ru/3.7/library/doctest.html#what-s-the-execution-context)
    - [А как насчёт исключений?](https://python-all.ru/3.7/library/doctest.html#what-about-exceptions)
    - [Флаги опций](https://python-all.ru/3.7/library/doctest.html#option-flags)
    - [Директивы](https://python-all.ru/3.7/library/doctest.html#directives)
    - [Предупреждения](https://python-all.ru/3.7/library/doctest.html#warnings)
  - [Базовый API](https://python-all.ru/3.7/library/doctest.html#basic-api)
  - [API unittest](https://python-all.ru/3.7/library/doctest.html#unittest-api)
  - [Расширенный API](https://python-all.ru/3.7/library/doctest.html#advanced-api)

    - [Объекты DocTest](https://python-all.ru/3.7/library/doctest.html#doctest-objects)
    - [Объекты Example](https://python-all.ru/3.7/library/doctest.html#example-objects)
    - [Объекты DocTestFinder](https://python-all.ru/3.7/library/doctest.html#doctestfinder-objects)
    - [Объекты DocTestParser](https://python-all.ru/3.7/library/doctest.html#doctestparser-objects)
    - [Объекты DocTestRunner](https://python-all.ru/3.7/library/doctest.html#doctestrunner-objects)
    - [Объекты OutputChecker](https://python-all.ru/3.7/library/doctest.html#outputchecker-objects)
  - [Отладка](https://python-all.ru/3.7/library/doctest.html#debugging)
  - [Трибуна](https://python-all.ru/3.7/library/doctest.html#soapbox)
- [`unittest` – фреймворк для модульного тестирования](https://python-all.ru/3.7/library/unittest.html)

  - [Простой пример](https://python-all.ru/3.7/library/unittest.html#basic-example)
  - [Интерфейс командной строки](https://python-all.ru/3.7/library/unittest.html#command-line-interface)

    - [Параметры командной строки](https://python-all.ru/3.7/library/unittest.html#command-line-options)
  - [Обнаружение тестов](https://python-all.ru/3.7/library/unittest.html#test-discovery)
  - [Организация тестового кода](https://python-all.ru/3.7/library/unittest.html#organizing-test-code)
  - [Повторное использование старого тестового кода](https://python-all.ru/3.7/library/unittest.html#re-using-old-test-code)
  - [Пропуск тестов и ожидаемые сбои](https://python-all.ru/3.7/library/unittest.html#skipping-tests-and-expected-failures)
  - [Различение итераций теста с помощью подтестов](https://python-all.ru/3.7/library/unittest.html#distinguishing-test-iterations-using-subtests)
  - [Классы и функции](https://python-all.ru/3.7/library/unittest.html#classes-and-functions)

    - [Тестовые случаи](https://python-all.ru/3.7/library/unittest.html#test-cases)

      - [Устаревшие псевдонимы](https://python-all.ru/3.7/library/unittest.html#deprecated-aliases)
    - [Группировка тестов](https://python-all.ru/3.7/library/unittest.html#grouping-tests)
    - [Загрузка и запуск тестов](https://python-all.ru/3.7/library/unittest.html#loading-and-running-tests)

      - [Протокол load\_tests](https://python-all.ru/3.7/library/unittest.html#load-tests-protocol)
  - [Фикстуры классов и модулей](https://python-all.ru/3.7/library/unittest.html#class-and-module-fixtures)

    - [setUpClass и tearDownClass](https://python-all.ru/3.7/library/unittest.html#setupclass-and-teardownclass)
    - [setUpModule и tearDownModule](https://python-all.ru/3.7/library/unittest.html#setupmodule-and-teardownmodule)
  - [Обработка сигналов](https://python-all.ru/3.7/library/unittest.html#signal-handling)
- [`unittest.mock` – библиотека mock-объектов](https://python-all.ru/3.7/library/unittest.mock.html)

  - [Краткое руководство](https://python-all.ru/3.7/library/unittest.mock.html#quick-guide)
  - [Класс Mock](https://python-all.ru/3.7/library/unittest.mock.html#the-mock-class)

    - [Вызов](https://python-all.ru/3.7/library/unittest.mock.html#calling)
    - [Удаление атрибутов](https://python-all.ru/3.7/library/unittest.mock.html#deleting-attributes)
    - [Имена Mock и атрибут name](https://python-all.ru/3.7/library/unittest.mock.html#mock-names-and-the-name-attribute)
    - [Прикрепление моков в качестве атрибутов](https://python-all.ru/3.7/library/unittest.mock.html#attaching-mocks-as-attributes)
  - [Патчеры](https://python-all.ru/3.7/library/unittest.mock.html#the-patchers)

    - [patch](https://python-all.ru/3.7/library/unittest.mock.html#patch)
    - [patch.object](https://python-all.ru/3.7/library/unittest.mock.html#patch-object)
    - [patch.dict](https://python-all.ru/3.7/library/unittest.mock.html#patch-dict)
    - [patch.multiple](https://python-all.ru/3.7/library/unittest.mock.html#patch-multiple)
    - [Методы patch: start и stop](https://python-all.ru/3.7/library/unittest.mock.html#patch-methods-start-and-stop)
    - [patch встроенных объектов](https://python-all.ru/3.7/library/unittest.mock.html#patch-builtins)
    - [TEST\_PREFIX](https://python-all.ru/3.7/library/unittest.mock.html#test-prefix)
    - [Вложение декораторов patch](https://python-all.ru/3.7/library/unittest.mock.html#nesting-patch-decorators)
    - [Где применять patch](https://python-all.ru/3.7/library/unittest.mock.html#where-to-patch)
    - [Подмена дескрипторов и прокси-объектов](https://python-all.ru/3.7/library/unittest.mock.html#patching-descriptors-and-proxy-objects)
  - [MagicMock и поддержка магических методов](https://python-all.ru/3.7/library/unittest.mock.html#magicmock-and-magic-method-support)

    - [Мокирование магических методов](https://python-all.ru/3.7/library/unittest.mock.html#mocking-magic-methods)
    - [Магический макет](https://python-all.ru/3.7/library/unittest.mock.html#magic-mock)
  - [Вспомогательные средства](https://python-all.ru/3.7/library/unittest.mock.html#helpers)

    - [sentinel](https://python-all.ru/3.7/library/unittest.mock.html#sentinel)
    - [DEFAULT](https://python-all.ru/3.7/library/unittest.mock.html#default)
    - [вызов](https://python-all.ru/3.7/library/unittest.mock.html#call)
    - [create\_autospec](https://python-all.ru/3.7/library/unittest.mock.html#create-autospec)
    - [ANY](https://python-all.ru/3.7/library/unittest.mock.html#any)
    - [FILTER\_DIR](https://python-all.ru/3.7/library/unittest.mock.html#filter-dir)
    - [mock\_open](https://python-all.ru/3.7/library/unittest.mock.html#mock-open)
    - [Автоспецификация](https://python-all.ru/3.7/library/unittest.mock.html#autospeccing)
    - [Запечатывание моков](https://python-all.ru/3.7/library/unittest.mock.html#sealing-mocks)
- [`unittest.mock` – начало работы](https://python-all.ru/3.7/library/unittest.mock-examples.html)

  - [Использование Mock](https://python-all.ru/3.7/library/unittest.mock-examples.html#using-mock)

    - [Методы подмены моков](https://python-all.ru/3.7/library/unittest.mock-examples.html#mock-patching-methods)
    - [Mock для вызовов методов объекта](https://python-all.ru/3.7/library/unittest.mock-examples.html#mock-for-method-calls-on-an-object)
    - [Создание моков для классов](https://python-all.ru/3.7/library/unittest.mock-examples.html#mocking-classes)
    - [Именование моков](https://python-all.ru/3.7/library/unittest.mock-examples.html#naming-your-mocks)
    - [Отслеживание всех вызовов](https://python-all.ru/3.7/library/unittest.mock-examples.html#tracking-all-calls)
    - [Установка возвращаемых значений и атрибутов](https://python-all.ru/3.7/library/unittest.mock-examples.html#setting-return-values-and-attributes)
    - [Возбуждение исключений с помощью моков](https://python-all.ru/3.7/library/unittest.mock-examples.html#raising-exceptions-with-mocks)
    - [Функции побочного эффекта и итерируемые объекты](https://python-all.ru/3.7/library/unittest.mock-examples.html#side-effect-functions-and-iterables)
    - [Создание мока на основе существующего объекта](https://python-all.ru/3.7/library/unittest.mock-examples.html#creating-a-mock-from-an-existing-object)
  - [Декораторы patch](https://python-all.ru/3.7/library/unittest.mock-examples.html#patch-decorators)
  - [Дополнительные примеры](https://python-all.ru/3.7/library/unittest.mock-examples.html#further-examples)

    - [Мокирование цепочек вызовов](https://python-all.ru/3.7/library/unittest.mock-examples.html#mocking-chained-calls)
    - [Частичное мокирование](https://python-all.ru/3.7/library/unittest.mock-examples.html#partial-mocking)
    - [Создание мока для метода-генератора](https://python-all.ru/3.7/library/unittest.mock-examples.html#mocking-a-generator-method)
    - [Применение одного и того же patch к каждому тестовому методу](https://python-all.ru/3.7/library/unittest.mock-examples.html#applying-the-same-patch-to-every-test-method)
    - [Создание моков для несвязанных методов](https://python-all.ru/3.7/library/unittest.mock-examples.html#mocking-unbound-methods)
    - [Проверка множественных вызовов с помощью mock](https://python-all.ru/3.7/library/unittest.mock-examples.html#checking-multiple-calls-with-mock)
    - [Работа с изменяемыми аргументами](https://python-all.ru/3.7/library/unittest.mock-examples.html#coping-with-mutable-arguments)
    - [Вложенные подмены](https://python-all.ru/3.7/library/unittest.mock-examples.html#nesting-patches)
    - [Мокирование словаря с помощью MagicMock](https://python-all.ru/3.7/library/unittest.mock-examples.html#mocking-a-dictionary-with-magicmock)
    - [Подклассы Mock и их атрибуты](https://python-all.ru/3.7/library/unittest.mock-examples.html#mock-subclasses-and-their-attributes)
    - [Мокирование импортов с помощью patch.dict](https://python-all.ru/3.7/library/unittest.mock-examples.html#mocking-imports-with-patch-dict)
    - [Отслеживание порядка вызовов и менее многословные утверждения о вызовах](https://python-all.ru/3.7/library/unittest.mock-examples.html#tracking-order-of-calls-and-less-verbose-call-assertions)
    - [Более сложное сопоставление аргументов](https://python-all.ru/3.7/library/unittest.mock-examples.html#more-complex-argument-matching)
- [2to3 – автоматический перенос кода с Python 2 на Python 3](https://python-all.ru/3.7/library/2to3.html)

  - [Использование 2to3](https://python-all.ru/3.7/library/2to3.html#using-2to3)
  - [Фиксы](https://python-all.ru/3.7/library/2to3.html#fixers)
  - [`lib2to3` – библиотека 2to3](https://python-all.ru/3.7/library/2to3.html#module-lib2to3)
- [`test` – Пакет регрессионных тестов для Python](https://python-all.ru/3.7/library/test.html)

  - [Написание модульных тестов для пакета `test`](https://python-all.ru/3.7/library/test.html#writing-unit-tests-for-the-test-package)
  - [Запуск тестов с помощью интерфейса командной строки](https://python-all.ru/3.7/library/test.html#running-tests-using-the-command-line-interface)
- [`test.support` – Утилиты для набора тестов Python](https://python-all.ru/3.7/library/test.html#module-test.support)
- [`test.support.script_helper` – Утилиты для тестов выполнения Python](https://python-all.ru/3.7/library/test.html#module-test.support.script_helper)

См. также режим разработки Python: параметр [`-X`](https://python-all.ru/3.7/using/cmdline.html#id5) `dev` и переменная окружения [`PYTHONDEVMODE`](https://python-all.ru/3.7/using/cmdline.html#envvar-PYTHONDEVMODE).
