💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](typing.xhtml "typing --- 类型标注支持") | - [上一页](othergui.xhtml "其他图形用户界面(GUI)包") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - $('.inline-search').show(0); | # 开发工具 本章中描述的各模块可帮你编写 Python 程序。例如,[`pydoc`](pydoc.xhtml#module-pydoc "pydoc: Documentation generator and online help system.") 模块接受一个模块并根据该模块的内容来生成文档。[`doctest`](doctest.xhtml#module-doctest "doctest: Test pieces of code within docstrings.") 和 [`unittest`](unittest.xhtml#module-unittest "unittest: Unit testing framework for Python.") 这两个模块包含了用于编写单元测试的框架,并可用于自动测试所编写的代码,验证预期的输出是否产生。**2to3** 程序能够将 Python 2.x 源代码翻译成有效的 Python 3.x 源代码。 本章中描述的模块列表是: - [`typing` --- 类型标注支持](typing.xhtml) - [类型别名](typing.xhtml#type-aliases) - [NewType](typing.xhtml#newtype) - [Callable](typing.xhtml#callable) - [泛型(Generic)](typing.xhtml#generics) - [用户定义的泛型类型](typing.xhtml#user-defined-generic-types) - [`Any` 类型](typing.xhtml#the-any-type) - [类,函数和修饰器.](typing.xhtml#classes-functions-and-decorators) - [`pydoc` --- Documentation generator and online help system](pydoc.xhtml) - [`doctest` --- Test interactive Python examples](doctest.xhtml) - [Simple Usage: Checking Examples in Docstrings](doctest.xhtml#simple-usage-checking-examples-in-docstrings) - [Simple Usage: Checking Examples in a Text File](doctest.xhtml#simple-usage-checking-examples-in-a-text-file) - [How It Works](doctest.xhtml#how-it-works) - [Which Docstrings Are Examined?](doctest.xhtml#which-docstrings-are-examined) - [How are Docstring Examples Recognized?](doctest.xhtml#how-are-docstring-examples-recognized) - [What's the Execution Context?](doctest.xhtml#what-s-the-execution-context) - [What About Exceptions?](doctest.xhtml#what-about-exceptions) - [Option Flags](doctest.xhtml#option-flags) - [Directives](doctest.xhtml#directives) - [警告](doctest.xhtml#warnings) - [Basic API](doctest.xhtml#basic-api) - [Unittest API](doctest.xhtml#unittest-api) - [Advanced API](doctest.xhtml#advanced-api) - [DocTest Objects](doctest.xhtml#doctest-objects) - [Example Objects](doctest.xhtml#example-objects) - [DocTestFinder objects](doctest.xhtml#doctestfinder-objects) - [DocTestParser objects](doctest.xhtml#doctestparser-objects) - [DocTestRunner objects](doctest.xhtml#doctestrunner-objects) - [OutputChecker objects](doctest.xhtml#outputchecker-objects) - [调试](doctest.xhtml#debugging) - [Soapbox](doctest.xhtml#soapbox) - [`unittest` --- 单元测试框架](unittest.xhtml) - [基本实例](unittest.xhtml#basic-example) - [命令行界面](unittest.xhtml#command-line-interface) - [命令行选项](unittest.xhtml#command-line-options) - [探索性测试](unittest.xhtml#test-discovery) - [组织你的测试代码](unittest.xhtml#organizing-test-code) - [复用已有的测试代码](unittest.xhtml#re-using-old-test-code) - [Skipping tests and expected failures](unittest.xhtml#skipping-tests-and-expected-failures) - [Distinguishing test iterations using subtests](unittest.xhtml#distinguishing-test-iterations-using-subtests) - [Classes and functions](unittest.xhtml#classes-and-functions) - [Test cases](unittest.xhtml#test-cases) - [Deprecated aliases](unittest.xhtml#deprecated-aliases) - [Grouping tests](unittest.xhtml#grouping-tests) - [Loading and running tests](unittest.xhtml#loading-and-running-tests) - [load\_tests Protocol](unittest.xhtml#load-tests-protocol) - [Class and Module Fixtures](unittest.xhtml#class-and-module-fixtures) - [setUpClass and tearDownClass](unittest.xhtml#setupclass-and-teardownclass) - [setUpModule and tearDownModule](unittest.xhtml#setupmodule-and-teardownmodule) - [Signal Handling](unittest.xhtml#signal-handling) - [`unittest.mock` --- mock object library](unittest.mock.xhtml) - [Quick Guide](unittest.mock.xhtml#quick-guide) - [The Mock Class](unittest.mock.xhtml#the-mock-class) - [Calling](unittest.mock.xhtml#calling) - [Deleting Attributes](unittest.mock.xhtml#deleting-attributes) - [Mock names and the name attribute](unittest.mock.xhtml#mock-names-and-the-name-attribute) - [Attaching Mocks as Attributes](unittest.mock.xhtml#attaching-mocks-as-attributes) - [The patchers](unittest.mock.xhtml#the-patchers) - [patch](unittest.mock.xhtml#patch) - [patch.object](unittest.mock.xhtml#patch-object) - [patch.dict](unittest.mock.xhtml#patch-dict) - [patch.multiple](unittest.mock.xhtml#patch-multiple) - [patch methods: start and stop](unittest.mock.xhtml#patch-methods-start-and-stop) - [patch builtins](unittest.mock.xhtml#patch-builtins) - [TEST\_PREFIX](unittest.mock.xhtml#test-prefix) - [Nesting Patch Decorators](unittest.mock.xhtml#nesting-patch-decorators) - [Where to patch](unittest.mock.xhtml#where-to-patch) - [Patching Descriptors and Proxy Objects](unittest.mock.xhtml#patching-descriptors-and-proxy-objects) - [MagicMock and magic method support](unittest.mock.xhtml#magicmock-and-magic-method-support) - [Mocking Magic Methods](unittest.mock.xhtml#mocking-magic-methods) - [Magic Mock](unittest.mock.xhtml#magic-mock) - [Helpers](unittest.mock.xhtml#helpers) - [sentinel](unittest.mock.xhtml#sentinel) - [DEFAULT](unittest.mock.xhtml#default) - [call](unittest.mock.xhtml#call) - [create\_autospec](unittest.mock.xhtml#create-autospec) - [ANY](unittest.mock.xhtml#any) - [FILTER\_DIR](unittest.mock.xhtml#filter-dir) - [mock\_open](unittest.mock.xhtml#mock-open) - [Autospeccing](unittest.mock.xhtml#autospeccing) - [Sealing mocks](unittest.mock.xhtml#sealing-mocks) - [`unittest.mock` 上手指南](unittest.mock-examples.xhtml) - [使用 mock](unittest.mock-examples.xhtml#using-mock) - [模拟方法调用](unittest.mock-examples.xhtml#mock-patching-methods) - [对象上的方法调用的 mock](unittest.mock-examples.xhtml#mock-for-method-calls-on-an-object) - [Mocking Classes](unittest.mock-examples.xhtml#mocking-classes) - [Naming your mocks](unittest.mock-examples.xhtml#naming-your-mocks) - [Tracking all Calls](unittest.mock-examples.xhtml#tracking-all-calls) - [Setting Return Values and Attributes](unittest.mock-examples.xhtml#setting-return-values-and-attributes) - [Raising exceptions with mocks](unittest.mock-examples.xhtml#raising-exceptions-with-mocks) - [Side effect functions and iterables](unittest.mock-examples.xhtml#side-effect-functions-and-iterables) - [Creating a Mock from an Existing Object](unittest.mock-examples.xhtml#creating-a-mock-from-an-existing-object) - [Patch Decorators](unittest.mock-examples.xhtml#patch-decorators) - [Further Examples](unittest.mock-examples.xhtml#further-examples) - [Mocking chained calls](unittest.mock-examples.xhtml#mocking-chained-calls) - [Partial mocking](unittest.mock-examples.xhtml#partial-mocking) - [Mocking a Generator Method](unittest.mock-examples.xhtml#mocking-a-generator-method) - [Applying the same patch to every test method](unittest.mock-examples.xhtml#applying-the-same-patch-to-every-test-method) - [Mocking Unbound Methods](unittest.mock-examples.xhtml#mocking-unbound-methods) - [Checking multiple calls with mock](unittest.mock-examples.xhtml#checking-multiple-calls-with-mock) - [Coping with mutable arguments](unittest.mock-examples.xhtml#coping-with-mutable-arguments) - [Nesting Patches](unittest.mock-examples.xhtml#nesting-patches) - [Mocking a dictionary with MagicMock](unittest.mock-examples.xhtml#mocking-a-dictionary-with-magicmock) - [Mock subclasses and their attributes](unittest.mock-examples.xhtml#mock-subclasses-and-their-attributes) - [Mocking imports with patch.dict](unittest.mock-examples.xhtml#mocking-imports-with-patch-dict) - [Tracking order of calls and less verbose call assertions](unittest.mock-examples.xhtml#tracking-order-of-calls-and-less-verbose-call-assertions) - [More complex argument matching](unittest.mock-examples.xhtml#more-complex-argument-matching) - [2to3 - 自动将 Python 2 代码转为 Python 3 代码](2to3.xhtml) - [使用 2to3](2to3.xhtml#using-2to3) - [修复器](2to3.xhtml#fixers) - [`lib2to3` —— 2to3 支持库](2to3.xhtml#module-lib2to3) - [`test` --- Regression tests package for Python](test.xhtml) - [Writing Unit Tests for the `test` package](test.xhtml#writing-unit-tests-for-the-test-package) - [Running tests using the command-line interface](test.xhtml#running-tests-using-the-command-line-interface) - [`test.support` --- Utilities for the Python test suite](test.xhtml#module-test.support) - [`test.support.script_helper` --- Utilities for the Python execution tests](test.xhtml#module-test.support.script_helper) 另请参看 Python 开发模式: [`-X`](../using/cmdline.xhtml#id5)`dev` 选项以及 [`PYTHONDEVMODE`](../using/cmdline.xhtml#envvar-PYTHONDEVMODE) 环境变量。 ### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](typing.xhtml "typing --- 类型标注支持") | - [上一页](othergui.xhtml "其他图形用户界面(GUI)包") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - $('.inline-search').show(0); | © [版权所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 软件基金会是一个非盈利组织。 [请捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [发现了问题](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 创建。