开发工具¶
本章中描述的各模块可帮你编写 Python 程序。例如,pydoc
模块接受一个模块并根据该模块的内容来生成文档。doctest
和 unittest
这两个模块包含了用于编写单元测试的框架,并可用于自动测试所编写的代码,验证预期的输出是否产生。2to3 程序能够将 Python 2.x 源代码翻译成有效的 Python 3.x 源代码。
本章中描述的模块列表是:
typing
--- 类型标注支持pydoc
--- Documentation generator and online help systemdoctest
--- 测试交互性的Python示例unittest
--- 单元测试框架unittest.mock
--- mock对象库unittest.mock
上手指南- 使用 mock
- Patch Decorators
- Further Examples
- Mocking chained calls
- Partial mocking
- Mocking a Generator Method
- Applying the same patch to every test method
- Mocking Unbound Methods
- Checking multiple calls with mock
- Coping with mutable arguments
- Nesting Patches
- Mocking a dictionary with MagicMock
- Mock subclasses and their attributes
- Mocking imports with patch.dict
- Tracking order of calls and less verbose call assertions
- More complex argument matching
- 2to3 - 自动将 Python 2 代码转为 Python 3 代码
test
--- Regression tests package for Pythontest.support
--- Utilities for the Python test suitetest.support.script_helper
--- Utilities for the Python execution tests
另请参看 Python 开发模式: -X
dev
选项以及 PYTHONDEVMODE
环境变量。