开发工具 ¶
此章描述的模块帮助您编写软件。例如,
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.
此章描述的模块列表:
-
typing— 支持类型提示- Specification for the Python Type System
- 类型别名
- NewType
- Annotating callable objects
- 一般
- Annotating tuples
- The type of class objects
- Annotating generators and coroutines
- 用户定义一般类型
-
The
Anytype - 名义 vs 结构子类型
-
模块内容
- 特殊 typing 原语
- 协议
- ABCs for working with IO
- 函数和装饰器
- 自省帮手
- 常量
- Deprecated aliases
- 主要特征弃用时间线
-
pydoc— 文档编制生成器和在线帮助系统 - Python 开发模式
-
doctest— 测试交互 Python 范例- 简单用法:校验 docstring (文档字符串) 中的范例
- 简单用法:校验文本文件中的范例
- 它如何工作
- 基本 API
- Unittest API
- 高级 API
- 调试
- Soapbox
-
unittest— 单元测试框架- 基本范例
- 命令行接口
- 测试探索
- 组织测试代码
- 重用旧测试代码
- Skipping tests and expected failures
- Distinguishing test iterations using subtests
-
类和函数
-
Test cases
-
TestCase-
setUp() -
tearDown() -
setUpClass() -
tearDownClass() -
run() -
skipTest() -
subTest() -
debug() -
assertEqual() -
assertNotEqual() -
assertTrue() -
assertFalse() -
assertIs() -
assertIsNot() -
assertIsNone() -
assertIsNotNone() -
assertIn() -
assertNotIn() -
assertIsInstance() -
assertNotIsInstance() -
assertRaises() -
assertRaisesRegex() -
assertWarns() -
assertWarnsRegex() -
assertLogs() -
assertNoLogs() -
assertAlmostEqual() -
assertNotAlmostEqual() -
assertGreater() -
assertGreaterEqual() -
assertLess() -
assertLessEqual() -
assertRegex() -
assertNotRegex() -
assertCountEqual() -
addTypeEqualityFunc() -
assertMultiLineEqual() -
assertSequenceEqual() -
assertListEqual() -
assertTupleEqual() -
assertSetEqual() -
assertDictEqual() -
fail() -
failureException -
longMessage -
maxDiff -
countTestCases() -
defaultTestResult() -
id() -
shortDescription() -
addCleanup() -
enterContext() -
doCleanups() -
addClassCleanup() -
enterClassContext() -
doClassCleanups()
-
-
IsolatedAsyncioTestCase -
FunctionTestCase
-
- Grouping tests
-
Loading and running tests
-
TestLoader -
TestResult-
errors -
failures -
skipped -
expectedFailures -
unexpectedSuccesses -
collectedDurations -
shouldStop -
testsRun -
buffer -
failfast -
tb_locals -
wasSuccessful() -
stop() -
startTest() -
stopTest() -
startTestRun() -
stopTestRun() -
addError() -
addFailure() -
addSuccess() -
addSkip() -
addExpectedFailure() -
addUnexpectedSuccess() -
addSubTest() -
addDuration()
-
-
TextTestResult -
defaultTestLoader -
TextTestRunner -
main() - load_tests Protocol
-
-
Test cases
- Class and Module Fixtures
- 信号处理
-
unittest.mock— 仿造对象库- Quick Guide
-
The Mock Class
-
Mock-
assert_called() -
assert_called_once() -
assert_called_with() -
assert_called_once_with() -
assert_any_call() -
assert_has_calls() -
assert_not_called() -
reset_mock() -
mock_add_spec() -
attach_mock() -
configure_mock() -
__dir__() -
_get_child_mock() -
called -
call_count -
return_value -
side_effect -
call_args -
call_args_list -
method_calls -
mock_calls -
__class__
-
-
NonCallableMock -
PropertyMock -
AsyncMock -
ThreadingMock - 调用
- Deleting Attributes
- Mock names and the name attribute
- Attaching Mocks as Attributes
-
- The patchers
- MagicMock and magic method support
- 帮手
-
Order of precedence of
side_effect,return_valueand wraps
-
unittest.mock— 快速入门-
Using Mock
- Mock Patching Methods
- Mock for Method Calls on an Object
- Mocking Classes
- Naming your mocks
- 追踪所有调用
- Setting Return Values and Attributes
- Raising exceptions with mocks
- Side effect functions and iterables
- Mocking asynchronous iterators
- Mocking asynchronous context manager
- Creating a Mock from an Existing Object
- Using side_effect to return per file content
- 补丁装饰器
-
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
- 嵌套补丁
- 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
-
Using Mock
-
test— 用于 Python 的回归测试包 -
test.support— 用于 Python 测试套件的实用程序-
TestFailed -
ResourceDenied -
verbose -
is_jython -
is_android -
unix_shell -
LOOPBACK_TIMEOUT -
INTERNET_TIMEOUT -
SHORT_TIMEOUT -
LONG_TIMEOUT -
PGO -
PIPE_MAX_SIZE -
Py_DEBUG -
SOCK_MAX_SIZE -
TEST_SUPPORT_DIR -
TEST_HOME_DIR -
TEST_DATA_DIR -
MAX_Py_ssize_t -
max_memuse -
real_max_memuse -
MISSING_C_DOCSTRINGS -
HAVE_DOCSTRINGS -
TEST_HTTP_URL -
ALWAYS_EQ -
NEVER_EQ -
LARGEST -
SMALLEST -
busy_retry() -
sleeping_retry() -
is_resource_enabled() -
python_is_optimized() -
with_pymalloc() -
requires() -
sortdict() -
findfile() -
get_pagesize() -
setswitchinterval() -
check_impl_detail() -
set_memlimit() -
record_original_stdout() -
get_original_stdout() -
args_from_interpreter_flags() -
optim_args_from_interpreter_flags() -
captured_stdin() -
captured_stdout() -
captured_stderr() -
disable_faulthandler() -
gc_collect() -
disable_gc() -
swap_attr() -
swap_item() -
flush_std_streams() -
print_warning() -
wait_process() -
calcobjsize() -
calcvobjsize() -
checksizeof() -
anticipate_failure() -
system_must_validate_cert() -
run_with_locale() -
run_with_tz() -
requires_freebsd_version() -
requires_linux_version() -
requires_mac_version() -
requires_gil_enabled() -
requires_IEEE_754() -
requires_zlib() -
requires_gzip() -
requires_bz2() -
requires_lzma() -
requires_resource() -
requires_docstrings() -
requires_limited_api() -
cpython_only() -
impl_detail() -
no_tracing() -
refcount_test() -
bigmemtest() -
bigaddrspacetest() -
check_syntax_error() -
open_urlresource() -
reap_children() -
get_attribute() -
catch_unraisable_exception() -
load_package_tests() -
detect_api_mismatch() -
patch() -
run_in_subinterp() -
check_free_after_iterating() -
missing_compiler_executable() -
check__all__() -
skip_if_broken_multiprocessing_synchronize() -
check_disallow_instantiation() -
adjust_int_max_str_digits() -
SuppressCrashReport -
SaveSignals -
Matcher
-
-
test.support.socket_helper— 用于套接字测试的实用程序 -
test.support.script_helper— 用于 Python 执行测试的实用程序 -
test.support.bytecode_helper— 用于测试正确字节码生成的支持工具 -
test.support.threading_helper— 用于线程测试的实用程序 -
test.support.os_helper— 用于 OS 测试的实用程序-
FS_NONASCII -
SAVEDCWD -
TESTFN -
TESTFN_NONASCII -
TESTFN_UNENCODABLE -
TESTFN_UNDECODABLE -
TESTFN_UNICODE -
EnvironmentVarGuard -
FakePath -
set() -
unset() -
can_symlink() -
can_xattr() -
change_cwd() -
create_empty_file() -
fd_count() -
fs_is_case_insensitive() -
make_bad_fd() -
rmdir() -
rmtree() -
skip_unless_symlink() -
skip_unless_xattr() -
temp_cwd() -
temp_dir() -
temp_umask() -
unlink()
-
-
test.support.import_helper— 用于导入测试的实用程序 -
test.support.warnings_helper— 用于警告测试的实用程序