27. 開發工具¶
The modules described in this chapter help you write software. For example, the
pydoc
module takes a module and generates documentation based on the
module’s contents. The doctest
and unittest
modules contains
frameworks for writing unit tests that automatically exercise code and verify
that the expected output is produced. 2to3 can translate Python 2.x
source code into valid Python 3.x code.
The list of modules described in this chapter is:
- 27.1.
typing
— Support for type hints - 27.2.
pydoc
— Documentation generator and online help system - 27.3.
doctest
— Test interactive Python examples - 27.4.
unittest
— 單元測試框架- 27.4.1. 簡單範例
- 27.4.2. 命令執行列介面 (Command-Line Interface)
- 27.4.3. Test Discovery(測試探索)
- 27.4.4. Organizing test code
- 27.4.5. Re-using old test code
- 27.4.6. Skipping tests and expected failures
- 27.4.7. Distinguishing test iterations using subtests
- 27.4.8. Classes and functions
- 27.4.9. Class and Module Fixtures
- 27.4.10. Signal Handling
- 27.5.
unittest.mock
— mock object library - 27.6.
unittest.mock
— getting started- 27.6.1. Using Mock
- 27.6.1.1. Mock Patching Methods
- 27.6.1.2. Mock for Method Calls on an Object
- 27.6.1.3. Mocking Classes
- 27.6.1.4. Naming your mocks
- 27.6.1.5. Tracking all Calls
- 27.6.1.6. Setting Return Values and Attributes
- 27.6.1.7. Raising exceptions with mocks
- 27.6.1.8. Side effect functions and iterables
- 27.6.1.9. Creating a Mock from an Existing Object
- 27.6.2. Patch Decorators
- 27.6.3. Further Examples
- 27.6.3.1. Mocking chained calls
- 27.6.3.2. Partial mocking
- 27.6.3.3. Mocking a Generator Method
- 27.6.3.4. Applying the same patch to every test method
- 27.6.3.5. Mocking Unbound Methods
- 27.6.3.6. Checking multiple calls with mock
- 27.6.3.7. Coping with mutable arguments
- 27.6.3.8. Nesting Patches
- 27.6.3.9. Mocking a dictionary with MagicMock
- 27.6.3.10. Mock subclasses and their attributes
- 27.6.3.11. Mocking imports with patch.dict
- 27.6.3.12. Tracking order of calls and less verbose call assertions
- 27.6.3.13. More complex argument matching
- 27.6.1. Using Mock
- 27.7. 2to3 - 自動將 Python 2的程式碼轉成 Python 3
- 27.8.
test
— Regression tests package for Python - 27.9.
test.support
— Utilities for the Python test suite - 27.10.
test.support.script_helper
— Utilities for the Python execution tests
See also the Python development mode: the -X
dev
option and
PYTHONDEVMODE
environment variable.