開発ツール¶
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.
この章で解説されるモジュールのリスト:
typing
--- 型ヒントのサポート- Relevant PEPs
- 型エイリアス
- NewType
- 呼び出し可能オブジェクト
- ジェネリクス
- ユーザー定義のジェネリック型
Any
型- 名前的部分型 vs 構造的部分型
- モジュールの内容
- 特殊型付けプリミティブ
- Generic concrete collections
- 抽象基底クラス
- プロトコル
- Functions and decorators
- Introspection helpers
- 定数
- Deprecation Timeline of Major Features
pydoc
--- ドキュメント生成とオンラインヘルプシステム- Python 開発モード
- Effects of the Python Development Mode
- ResourceWarning Example
- Bad file descriptor error example
doctest
--- 対話的な実行例をテストする- 簡単な利用法: docstring 中の実行例をチェックする
- 簡単な利用法: テキストファイル中の実行例をチェックする
- doctest のからくり
- 基本 API
- 単体テスト API
- 拡張 API
- デバッグ
- アドバイス
unittest
--- ユニットテストフレームワーク- 基本的な例
- コマンドラインインターフェイス
- テストディスカバリ
- テストコードの構成
- 既存テストコードの再利用
- テストのスキップと予期された失敗
- サブテストを利用して繰り返しテストの区別を付ける
- クラスと関数
- テストクラス
TestCase
TestCase.setUp()
TestCase.tearDown()
TestCase.setUpClass()
TestCase.tearDownClass()
TestCase.run()
TestCase.skipTest()
TestCase.subTest()
TestCase.debug()
TestCase.assertEqual()
TestCase.assertNotEqual()
TestCase.assertTrue()
TestCase.assertFalse()
TestCase.assertIs()
TestCase.assertIsNot()
TestCase.assertIsNone()
TestCase.assertIsNotNone()
TestCase.assertIn()
TestCase.assertNotIn()
TestCase.assertIsInstance()
TestCase.assertNotIsInstance()
TestCase.assertRaises()
TestCase.assertRaisesRegex()
TestCase.assertWarns()
TestCase.assertWarnsRegex()
TestCase.assertLogs()
TestCase.records
TestCase.output
TestCase.assertNoLogs()
TestCase.assertAlmostEqual()
TestCase.assertNotAlmostEqual()
TestCase.assertGreater()
TestCase.assertGreaterEqual()
TestCase.assertLess()
TestCase.assertLessEqual()
TestCase.assertRegex()
TestCase.assertNotRegex()
TestCase.assertCountEqual()
TestCase.addTypeEqualityFunc()
TestCase.assertMultiLineEqual()
TestCase.assertSequenceEqual()
TestCase.assertListEqual()
TestCase.assertTupleEqual()
TestCase.assertSetEqual()
TestCase.assertDictEqual()
TestCase.fail()
TestCase.failureException
TestCase.longMessage
TestCase.maxDiff
TestCase.countTestCases()
TestCase.defaultTestResult()
TestCase.id()
TestCase.shortDescription()
TestCase.addCleanup()
TestCase.enterContext()
TestCase.doCleanups()
TestCase.addClassCleanup()
TestCase.enterClassContext()
TestCase.doClassCleanups()
IsolatedAsyncioTestCase
FunctionTestCase
- テストのグループ化
- テストのロードと起動
TestLoader
TestLoader.errors
TestLoader.loadTestsFromTestCase()
TestLoader.loadTestsFromModule()
TestLoader.loadTestsFromName()
TestLoader.loadTestsFromNames()
TestLoader.getTestCaseNames()
TestLoader.discover()
TestLoader.testMethodPrefix
TestLoader.sortTestMethodsUsing
TestLoader.suiteClass
TestLoader.testNamePatterns
TestResult
TestResult.errors
TestResult.failures
TestResult.skipped
TestResult.expectedFailures
TestResult.unexpectedSuccesses
TestResult.collectedDurations
TestResult.shouldStop
TestResult.testsRun
TestResult.buffer
TestResult.failfast
TestResult.tb_locals
TestResult.wasSuccessful()
TestResult.stop()
TestResult.startTest()
TestResult.stopTest()
TestResult.startTestRun()
TestResult.stopTestRun()
TestResult.addError()
TestResult.addFailure()
TestResult.addSuccess()
TestResult.addSkip()
TestResult.addExpectedFailure()
TestResult.addUnexpectedSuccess()
TestResult.addSubTest()
TestResult.addDuration()
TextTestResult
defaultTestLoader
TextTestRunner
main()
- load_tests プロトコル
- テストクラス
- クラスとモジュールのフィクスチャ
- シグナルハンドリング
unittest.mock
--- モックオブジェクトライブラリ- クイックガイド
- Mock クラス
Mock
Mock.assert_called()
Mock.assert_called_once()
Mock.assert_called_with()
Mock.assert_called_once_with()
Mock.assert_any_call()
Mock.assert_has_calls()
Mock.assert_not_called()
Mock.reset_mock()
Mock.mock_add_spec()
Mock.attach_mock()
Mock.configure_mock()
Mock.__dir__()
Mock._get_child_mock()
Mock.called
Mock.call_count
Mock.return_value
Mock.side_effect
Mock.call_args
Mock.call_args_list
Mock.method_calls
Mock.mock_calls
Mock.__class__
NonCallableMock
PropertyMock
AsyncMock
AsyncMock.assert_awaited()
AsyncMock.assert_awaited_once()
AsyncMock.assert_awaited_with()
AsyncMock.assert_awaited_once_with()
AsyncMock.assert_any_await()
AsyncMock.assert_has_awaits()
AsyncMock.assert_not_awaited()
AsyncMock.reset_mock()
AsyncMock.await_count
AsyncMock.await_args
AsyncMock.await_args_list
- 呼び出し
- 属性の削除
- Mock の名前と name 属性
- 属性として設定されるモック
- patcher
- MagicMock と magic method のサポート
- ヘルパー
unittest.mock
--- 入門test
--- Python 用回帰テストパッケージtest.support
--- テストのためのユーティリティ関数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()
match_test()
set_match_tests()
run_unittest()
run_doctest()
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_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
--- Utilities for socket teststest.support.script_helper
--- Utilities for the Python execution teststest.support.bytecode_helper
--- Support tools for testing correct bytecode generationtest.support.threading_helper
--- Utilities for threading teststest.support.os_helper
--- Utilities for os testsFS_NONASCII
SAVEDCWD
TESTFN
TESTFN_NONASCII
TESTFN_UNENCODABLE
TESTFN_UNDECODABLE
TESTFN_UNICODE
EnvironmentVarGuard
FakePath
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
--- Utilities for import teststest.support.warnings_helper
--- Utilities for warnings tests