Документация Python неофициальный перевод

development.md

154 строк · 16.6 КБ · обычная страница · сырой текст · скачать

1> **Источник:** https://python-all.ru/3.8/library/development.html2>3> «Документация Python на русском» – неофициальный перевод официальной документации Python: версии от 2.6 до 3.16, полнотекстовый поиск, английский оригинал рядом с переводом. Эта Markdown-версия страницы предназначена для работы с LLM: вставьте её в ChatGPT, Claude или Cursor.45---67# Инструменты разработки89Модули, описанные в этой главе, помогают писать программное обеспечение. Например, модуль [`pydoc`](https://python-all.ru/3.8/library/pydoc.html#module-pydoc) принимает модуль и генерирует документацию на основе его содержимого. Модули [`doctest`](https://python-all.ru/3.8/library/doctest.html#module-doctest) и [`unittest`](https://python-all.ru/3.8/library/unittest.html#module-unittest) содержат фреймворки для написания модульных тестов, которые автоматически выполняют код и проверяют, что вывод соответствует ожидаемому. **2to3** может переводить исходный код Python 2.x в корректный код Python 3.x.1011Список модулей, описанных в этой главе:1213- [`typing` – Поддержка аннотаций типов](https://python-all.ru/3.8/library/typing.html)1415  - [Псевдонимы типов](https://python-all.ru/3.8/library/typing.html#type-aliases)16  - [NewType](https://python-all.ru/3.8/library/typing.html#newtype)17  - [Callable](https://python-all.ru/3.8/library/typing.html#callable)18  - [Обобщённые типы](https://python-all.ru/3.8/library/typing.html#generics)19  - [Пользовательские обобщённые типы](https://python-all.ru/3.8/library/typing.html#user-defined-generic-types)20  - [Тип `Any`](https://python-all.ru/3.8/library/typing.html#the-any-type)21  - [Номинальное и структурное подтипирование](https://python-all.ru/3.8/library/typing.html#nominal-vs-structural-subtyping)22  - [Классы, функции и декораторы](https://python-all.ru/3.8/library/typing.html#classes-functions-and-decorators)23- [`pydoc` – генератор документации и система интерактивной справки](https://python-all.ru/3.8/library/pydoc.html)24- [`doctest` – тестирование интерактивных примеров Python](https://python-all.ru/3.8/library/doctest.html)2526  - [Простое использование: проверка примеров в строках документации](https://python-all.ru/3.8/library/doctest.html#simple-usage-checking-examples-in-docstrings)27  - [Простое использование: проверка примеров в текстовом файле](https://python-all.ru/3.8/library/doctest.html#simple-usage-checking-examples-in-a-text-file)28  - [Как это работает](https://python-all.ru/3.8/library/doctest.html#how-it-works)2930    - [Какие строки документации проверяются?](https://python-all.ru/3.8/library/doctest.html#which-docstrings-are-examined)31    - [Как распознаются примеры в строках документации?](https://python-all.ru/3.8/library/doctest.html#how-are-docstring-examples-recognized)32    - [Каков контекст выполнения?](https://python-all.ru/3.8/library/doctest.html#what-s-the-execution-context)33    - [А как насчёт исключений?](https://python-all.ru/3.8/library/doctest.html#what-about-exceptions)34    - [Флаги опций](https://python-all.ru/3.8/library/doctest.html#option-flags)35    - [Директивы](https://python-all.ru/3.8/library/doctest.html#directives)36    - [Предупреждения](https://python-all.ru/3.8/library/doctest.html#warnings)37  - [Базовый API](https://python-all.ru/3.8/library/doctest.html#basic-api)38  - [API unittest](https://python-all.ru/3.8/library/doctest.html#unittest-api)39  - [Расширенный API](https://python-all.ru/3.8/library/doctest.html#advanced-api)4041    - [Объекты DocTest](https://python-all.ru/3.8/library/doctest.html#doctest-objects)42    - [Объекты Example](https://python-all.ru/3.8/library/doctest.html#example-objects)43    - [Объекты DocTestFinder](https://python-all.ru/3.8/library/doctest.html#doctestfinder-objects)44    - [Объекты DocTestParser](https://python-all.ru/3.8/library/doctest.html#doctestparser-objects)45    - [Объекты DocTestRunner](https://python-all.ru/3.8/library/doctest.html#doctestrunner-objects)46    - [Объекты OutputChecker](https://python-all.ru/3.8/library/doctest.html#outputchecker-objects)47  - [Отладка](https://python-all.ru/3.8/library/doctest.html#debugging)48  - [Трибуна](https://python-all.ru/3.8/library/doctest.html#soapbox)49- [`unittest` – фреймворк для модульного тестирования](https://python-all.ru/3.8/library/unittest.html)5051  - [Простой пример](https://python-all.ru/3.8/library/unittest.html#basic-example)52  - [Интерфейс командной строки](https://python-all.ru/3.8/library/unittest.html#command-line-interface)5354    - [Параметры командной строки](https://python-all.ru/3.8/library/unittest.html#command-line-options)55  - [Обнаружение тестов](https://python-all.ru/3.8/library/unittest.html#test-discovery)56  - [Организация тестового кода](https://python-all.ru/3.8/library/unittest.html#organizing-test-code)57  - [Повторное использование старого тестового кода](https://python-all.ru/3.8/library/unittest.html#re-using-old-test-code)58  - [Пропуск тестов и ожидаемые сбои](https://python-all.ru/3.8/library/unittest.html#skipping-tests-and-expected-failures)59  - [Различение итераций теста с помощью подтестов](https://python-all.ru/3.8/library/unittest.html#distinguishing-test-iterations-using-subtests)60  - [Классы и функции](https://python-all.ru/3.8/library/unittest.html#classes-and-functions)6162    - [Тестовые случаи](https://python-all.ru/3.8/library/unittest.html#test-cases)6364      - [Устаревшие псевдонимы](https://python-all.ru/3.8/library/unittest.html#deprecated-aliases)65    - [Группировка тестов](https://python-all.ru/3.8/library/unittest.html#grouping-tests)66    - [Загрузка и запуск тестов](https://python-all.ru/3.8/library/unittest.html#loading-and-running-tests)6768      - [Протокол load\_tests](https://python-all.ru/3.8/library/unittest.html#load-tests-protocol)69  - [Фикстуры классов и модулей](https://python-all.ru/3.8/library/unittest.html#class-and-module-fixtures)7071    - [setUpClass и tearDownClass](https://python-all.ru/3.8/library/unittest.html#setupclass-and-teardownclass)72    - [setUpModule и tearDownModule](https://python-all.ru/3.8/library/unittest.html#setupmodule-and-teardownmodule)73  - [Обработка сигналов](https://python-all.ru/3.8/library/unittest.html#signal-handling)74- [`unittest.mock` – библиотека mock-объектов](https://python-all.ru/3.8/library/unittest.mock.html)7576  - [Краткое руководство](https://python-all.ru/3.8/library/unittest.mock.html#quick-guide)77  - [Класс Mock](https://python-all.ru/3.8/library/unittest.mock.html#the-mock-class)7879    - [Вызов](https://python-all.ru/3.8/library/unittest.mock.html#calling)80    - [Удаление атрибутов](https://python-all.ru/3.8/library/unittest.mock.html#deleting-attributes)81    - [Имена Mock и атрибут name](https://python-all.ru/3.8/library/unittest.mock.html#mock-names-and-the-name-attribute)82    - [Прикрепление моков в качестве атрибутов](https://python-all.ru/3.8/library/unittest.mock.html#attaching-mocks-as-attributes)83  - [Патчеры](https://python-all.ru/3.8/library/unittest.mock.html#the-patchers)8485    - [patch](https://python-all.ru/3.8/library/unittest.mock.html#patch)86    - [patch.object](https://python-all.ru/3.8/library/unittest.mock.html#patch-object)87    - [patch.dict](https://python-all.ru/3.8/library/unittest.mock.html#patch-dict)88    - [patch.multiple](https://python-all.ru/3.8/library/unittest.mock.html#patch-multiple)89    - [Методы patch: start и stop](https://python-all.ru/3.8/library/unittest.mock.html#patch-methods-start-and-stop)90    - [patch встроенных объектов](https://python-all.ru/3.8/library/unittest.mock.html#patch-builtins)91    - [TEST\_PREFIX](https://python-all.ru/3.8/library/unittest.mock.html#test-prefix)92    - [Вложение декораторов patch](https://python-all.ru/3.8/library/unittest.mock.html#nesting-patch-decorators)93    - [Где применять patch](https://python-all.ru/3.8/library/unittest.mock.html#where-to-patch)94    - [Подмена дескрипторов и прокси-объектов](https://python-all.ru/3.8/library/unittest.mock.html#patching-descriptors-and-proxy-objects)95  - [MagicMock и поддержка магических методов](https://python-all.ru/3.8/library/unittest.mock.html#magicmock-and-magic-method-support)9697    - [Мокирование магических методов](https://python-all.ru/3.8/library/unittest.mock.html#mocking-magic-methods)98    - [Магический макет](https://python-all.ru/3.8/library/unittest.mock.html#magic-mock)99  - [Вспомогательные средства](https://python-all.ru/3.8/library/unittest.mock.html#helpers)100101    - [sentinel](https://python-all.ru/3.8/library/unittest.mock.html#sentinel)102    - [DEFAULT](https://python-all.ru/3.8/library/unittest.mock.html#default)103    - [вызов](https://python-all.ru/3.8/library/unittest.mock.html#call)104    - [create\_autospec](https://python-all.ru/3.8/library/unittest.mock.html#create-autospec)105    - [ANY](https://python-all.ru/3.8/library/unittest.mock.html#any)106    - [FILTER\_DIR](https://python-all.ru/3.8/library/unittest.mock.html#filter-dir)107    - [mock\_open](https://python-all.ru/3.8/library/unittest.mock.html#mock-open)108    - [Автоспецификация](https://python-all.ru/3.8/library/unittest.mock.html#autospeccing)109    - [Запечатывание моков](https://python-all.ru/3.8/library/unittest.mock.html#sealing-mocks)110- [`unittest.mock` – начало работы](https://python-all.ru/3.8/library/unittest.mock-examples.html)111112  - [Использование Mock](https://python-all.ru/3.8/library/unittest.mock-examples.html#using-mock)113114    - [Методы подмены моков](https://python-all.ru/3.8/library/unittest.mock-examples.html#mock-patching-methods)115    - [Mock для вызовов методов объекта](https://python-all.ru/3.8/library/unittest.mock-examples.html#mock-for-method-calls-on-an-object)116    - [Создание моков для классов](https://python-all.ru/3.8/library/unittest.mock-examples.html#mocking-classes)117    - [Именование моков](https://python-all.ru/3.8/library/unittest.mock-examples.html#naming-your-mocks)118    - [Отслеживание всех вызовов](https://python-all.ru/3.8/library/unittest.mock-examples.html#tracking-all-calls)119    - [Установка возвращаемых значений и атрибутов](https://python-all.ru/3.8/library/unittest.mock-examples.html#setting-return-values-and-attributes)120    - [Возбуждение исключений с помощью моков](https://python-all.ru/3.8/library/unittest.mock-examples.html#raising-exceptions-with-mocks)121    - [Функции побочного эффекта и итерируемые объекты](https://python-all.ru/3.8/library/unittest.mock-examples.html#side-effect-functions-and-iterables)122    - [Мокирование асинхронных итераторов](https://python-all.ru/3.8/library/unittest.mock-examples.html#mocking-asynchronous-iterators)123    - [Мокирование асинхронного контекстного менеджера](https://python-all.ru/3.8/library/unittest.mock-examples.html#mocking-asynchronous-context-manager)124    - [Создание мока на основе существующего объекта](https://python-all.ru/3.8/library/unittest.mock-examples.html#creating-a-mock-from-an-existing-object)125  - [Декораторы patch](https://python-all.ru/3.8/library/unittest.mock-examples.html#patch-decorators)126  - [Дополнительные примеры](https://python-all.ru/3.8/library/unittest.mock-examples.html#further-examples)127128    - [Мокирование цепочек вызовов](https://python-all.ru/3.8/library/unittest.mock-examples.html#mocking-chained-calls)129    - [Частичное мокирование](https://python-all.ru/3.8/library/unittest.mock-examples.html#partial-mocking)130    - [Создание мока для метода-генератора](https://python-all.ru/3.8/library/unittest.mock-examples.html#mocking-a-generator-method)131    - [Применение одного и того же patch к каждому тестовому методу](https://python-all.ru/3.8/library/unittest.mock-examples.html#applying-the-same-patch-to-every-test-method)132    - [Создание моков для несвязанных методов](https://python-all.ru/3.8/library/unittest.mock-examples.html#mocking-unbound-methods)133    - [Проверка множественных вызовов с помощью mock](https://python-all.ru/3.8/library/unittest.mock-examples.html#checking-multiple-calls-with-mock)134    - [Работа с изменяемыми аргументами](https://python-all.ru/3.8/library/unittest.mock-examples.html#coping-with-mutable-arguments)135    - [Вложенные подмены](https://python-all.ru/3.8/library/unittest.mock-examples.html#nesting-patches)136    - [Мокирование словаря с помощью MagicMock](https://python-all.ru/3.8/library/unittest.mock-examples.html#mocking-a-dictionary-with-magicmock)137    - [Подклассы Mock и их атрибуты](https://python-all.ru/3.8/library/unittest.mock-examples.html#mock-subclasses-and-their-attributes)138    - [Мокирование импортов с помощью patch.dict](https://python-all.ru/3.8/library/unittest.mock-examples.html#mocking-imports-with-patch-dict)139    - [Отслеживание порядка вызовов и менее многословные утверждения о вызовах](https://python-all.ru/3.8/library/unittest.mock-examples.html#tracking-order-of-calls-and-less-verbose-call-assertions)140    - [Более сложное сопоставление аргументов](https://python-all.ru/3.8/library/unittest.mock-examples.html#more-complex-argument-matching)141- [2to3 – автоматический перенос кода с Python 2 на Python 3](https://python-all.ru/3.8/library/2to3.html)142143  - [Использование 2to3](https://python-all.ru/3.8/library/2to3.html#using-2to3)144  - [Фиксы](https://python-all.ru/3.8/library/2to3.html#fixers)145  - [`lib2to3` – библиотека 2to3](https://python-all.ru/3.8/library/2to3.html#module-lib2to3)146- [`test` – Пакет регрессионных тестов для Python](https://python-all.ru/3.8/library/test.html)147148  - [Написание модульных тестов для пакета `test`](https://python-all.ru/3.8/library/test.html#writing-unit-tests-for-the-test-package)149  - [Запуск тестов с помощью интерфейса командной строки](https://python-all.ru/3.8/library/test.html#running-tests-using-the-command-line-interface)150- [`test.support` – Утилиты для набора тестов Python](https://python-all.ru/3.8/library/test.html#module-test.support)151- [`test.support.script_helper` – Утилиты для тестов выполнения Python](https://python-all.ru/3.8/library/test.html#module-test.support.script_helper)152153См. также режим разработки Python: параметр [`-X`](https://python-all.ru/3.8/using/cmdline.html#id5) `dev` и переменная окружения [`PYTHONDEVMODE`](https://python-all.ru/3.8/using/cmdline.html#envvar-PYTHONDEVMODE).154