gooderp18绿色标准版
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

517 lines
36KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="Development Tools" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/development.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="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 modu..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="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 modu..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>Development Tools &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="typing — Support for type hints" href="typing.html" />
  33. <link rel="prev" title="IDLE" href="idle.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/development.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h4>Previous topic</h4>
  84. <p class="topless"><a href="idle.html"
  85. title="previous chapter">IDLE</a></p>
  86. </div>
  87. <div>
  88. <h4>Next topic</h4>
  89. <p class="topless"><a href="typing.html"
  90. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code> — Support for type hints</a></p>
  91. </div>
  92. <div role="note" aria-label="source link">
  93. <h3>This Page</h3>
  94. <ul class="this-page-menu">
  95. <li><a href="../bugs.html">Report a Bug</a></li>
  96. <li>
  97. <a href="https://github.com/python/cpython/blob/main/Doc/library/development.rst"
  98. rel="nofollow">Show Source
  99. </a>
  100. </li>
  101. </ul>
  102. </div>
  103. </nav>
  104. </div>
  105. </div>
  106. <div class="related" role="navigation" aria-label="related navigation">
  107. <h3>Navigation</h3>
  108. <ul>
  109. <li class="right" style="margin-right: 10px">
  110. <a href="../genindex.html" title="General Index"
  111. accesskey="I">index</a></li>
  112. <li class="right" >
  113. <a href="../py-modindex.html" title="Python Module Index"
  114. >modules</a> |</li>
  115. <li class="right" >
  116. <a href="typing.html" title="typing — Support for type hints"
  117. accesskey="N">next</a> |</li>
  118. <li class="right" >
  119. <a href="idle.html" title="IDLE"
  120. accesskey="P">previous</a> |</li>
  121. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  122. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  123. <li class="switchers">
  124. <div class="language_switcher_placeholder"></div>
  125. <div class="version_switcher_placeholder"></div>
  126. </li>
  127. <li>
  128. </li>
  129. <li id="cpython-language-and-version">
  130. <a href="../index.html">3.12.3 Documentation</a> &#187;
  131. </li>
  132. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">The Python Standard Library</a> &#187;</li>
  133. <li class="nav-item nav-item-this"><a href="">Development Tools</a></li>
  134. <li class="right">
  135. <div class="inline-search" role="search">
  136. <form class="inline-search" action="../search.html" method="get">
  137. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  138. <input type="submit" value="Go" />
  139. </form>
  140. </div>
  141. |
  142. </li>
  143. <li class="right">
  144. <label class="theme-selector-label">
  145. Theme
  146. <select class="theme-selector" oninput="activateTheme(this.value)">
  147. <option value="auto" selected>Auto</option>
  148. <option value="light">Light</option>
  149. <option value="dark">Dark</option>
  150. </select>
  151. </label> |</li>
  152. </ul>
  153. </div>
  154. <div class="document">
  155. <div class="documentwrapper">
  156. <div class="bodywrapper">
  157. <div class="body" role="main">
  158. <section id="development-tools">
  159. <span id="development"></span><h1>Development Tools<a class="headerlink" href="#development-tools" title="Link to this heading">¶</a></h1>
  160. <p>The modules described in this chapter help you write software. For example, the
  161. <a class="reference internal" href="pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> module takes a module and generates documentation based on the
  162. module’s contents. The <a class="reference internal" href="doctest.html#module-doctest" title="doctest: Test pieces of code within docstrings."><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code></a> and <a class="reference internal" href="unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> modules contains
  163. frameworks for writing unit tests that automatically exercise code and verify
  164. that the expected output is produced. <strong class="program">2to3</strong> can translate Python 2.x
  165. source code into valid Python 3.x code.</p>
  166. <p>The list of modules described in this chapter is:</p>
  167. <div class="toctree-wrapper compound">
  168. <ul>
  169. <li class="toctree-l1"><a class="reference internal" href="typing.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code> — Support for type hints</a><ul>
  170. <li class="toctree-l2"><a class="reference internal" href="typing.html#specification-for-the-python-type-system">Specification for the Python Type System</a></li>
  171. <li class="toctree-l2"><a class="reference internal" href="typing.html#type-aliases">Type aliases</a></li>
  172. <li class="toctree-l2"><a class="reference internal" href="typing.html#newtype">NewType</a></li>
  173. <li class="toctree-l2"><a class="reference internal" href="typing.html#annotating-callable-objects">Annotating callable objects</a></li>
  174. <li class="toctree-l2"><a class="reference internal" href="typing.html#generics">Generics</a></li>
  175. <li class="toctree-l2"><a class="reference internal" href="typing.html#annotating-tuples">Annotating tuples</a></li>
  176. <li class="toctree-l2"><a class="reference internal" href="typing.html#the-type-of-class-objects">The type of class objects</a></li>
  177. <li class="toctree-l2"><a class="reference internal" href="typing.html#user-defined-generic-types">User-defined generic types</a></li>
  178. <li class="toctree-l2"><a class="reference internal" href="typing.html#the-any-type">The <code class="xref py py-data docutils literal notranslate"><span class="pre">Any</span></code> type</a></li>
  179. <li class="toctree-l2"><a class="reference internal" href="typing.html#nominal-vs-structural-subtyping">Nominal vs structural subtyping</a></li>
  180. <li class="toctree-l2"><a class="reference internal" href="typing.html#module-contents">Module contents</a><ul>
  181. <li class="toctree-l3"><a class="reference internal" href="typing.html#special-typing-primitives">Special typing primitives</a><ul>
  182. <li class="toctree-l4"><a class="reference internal" href="typing.html#special-types">Special types</a></li>
  183. <li class="toctree-l4"><a class="reference internal" href="typing.html#special-forms">Special forms</a></li>
  184. <li class="toctree-l4"><a class="reference internal" href="typing.html#building-generic-types-and-type-aliases">Building generic types and type aliases</a></li>
  185. <li class="toctree-l4"><a class="reference internal" href="typing.html#other-special-directives">Other special directives</a></li>
  186. </ul>
  187. </li>
  188. <li class="toctree-l3"><a class="reference internal" href="typing.html#protocols">Protocols</a></li>
  189. <li class="toctree-l3"><a class="reference internal" href="typing.html#abcs-for-working-with-io">ABCs for working with IO</a></li>
  190. <li class="toctree-l3"><a class="reference internal" href="typing.html#functions-and-decorators">Functions and decorators</a></li>
  191. <li class="toctree-l3"><a class="reference internal" href="typing.html#introspection-helpers">Introspection helpers</a></li>
  192. <li class="toctree-l3"><a class="reference internal" href="typing.html#constant">Constant</a></li>
  193. <li class="toctree-l3"><a class="reference internal" href="typing.html#deprecated-aliases">Deprecated aliases</a><ul>
  194. <li class="toctree-l4"><a class="reference internal" href="typing.html#aliases-to-built-in-types">Aliases to built-in types</a></li>
  195. <li class="toctree-l4"><a class="reference internal" href="typing.html#aliases-to-types-in-collections">Aliases to types in <code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a></li>
  196. <li class="toctree-l4"><a class="reference internal" href="typing.html#aliases-to-other-concrete-types">Aliases to other concrete types</a></li>
  197. <li class="toctree-l4"><a class="reference internal" href="typing.html#aliases-to-container-abcs-in-collections-abc">Aliases to container ABCs in <code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a></li>
  198. <li class="toctree-l4"><a class="reference internal" href="typing.html#aliases-to-asynchronous-abcs-in-collections-abc">Aliases to asynchronous ABCs in <code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a></li>
  199. <li class="toctree-l4"><a class="reference internal" href="typing.html#aliases-to-other-abcs-in-collections-abc">Aliases to other ABCs in <code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a></li>
  200. <li class="toctree-l4"><a class="reference internal" href="typing.html#aliases-to-contextlib-abcs">Aliases to <code class="xref py py-mod docutils literal notranslate"><span class="pre">contextlib</span></code> ABCs</a></li>
  201. </ul>
  202. </li>
  203. </ul>
  204. </li>
  205. <li class="toctree-l2"><a class="reference internal" href="typing.html#deprecation-timeline-of-major-features">Deprecation Timeline of Major Features</a></li>
  206. </ul>
  207. </li>
  208. <li class="toctree-l1"><a class="reference internal" href="pydoc.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code> — Documentation generator and online help system</a></li>
  209. <li class="toctree-l1"><a class="reference internal" href="devmode.html">Python Development Mode</a><ul>
  210. <li class="toctree-l2"><a class="reference internal" href="devmode.html#effects-of-the-python-development-mode">Effects of the Python Development Mode</a></li>
  211. <li class="toctree-l2"><a class="reference internal" href="devmode.html#resourcewarning-example">ResourceWarning Example</a></li>
  212. <li class="toctree-l2"><a class="reference internal" href="devmode.html#bad-file-descriptor-error-example">Bad file descriptor error example</a></li>
  213. </ul>
  214. </li>
  215. <li class="toctree-l1"><a class="reference internal" href="doctest.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code> — Test interactive Python examples</a><ul>
  216. <li class="toctree-l2"><a class="reference internal" href="doctest.html#simple-usage-checking-examples-in-docstrings">Simple Usage: Checking Examples in Docstrings</a></li>
  217. <li class="toctree-l2"><a class="reference internal" href="doctest.html#simple-usage-checking-examples-in-a-text-file">Simple Usage: Checking Examples in a Text File</a></li>
  218. <li class="toctree-l2"><a class="reference internal" href="doctest.html#how-it-works">How It Works</a><ul>
  219. <li class="toctree-l3"><a class="reference internal" href="doctest.html#which-docstrings-are-examined">Which Docstrings Are Examined?</a></li>
  220. <li class="toctree-l3"><a class="reference internal" href="doctest.html#how-are-docstring-examples-recognized">How are Docstring Examples Recognized?</a></li>
  221. <li class="toctree-l3"><a class="reference internal" href="doctest.html#what-s-the-execution-context">What’s the Execution Context?</a></li>
  222. <li class="toctree-l3"><a class="reference internal" href="doctest.html#what-about-exceptions">What About Exceptions?</a></li>
  223. <li class="toctree-l3"><a class="reference internal" href="doctest.html#option-flags">Option Flags</a></li>
  224. <li class="toctree-l3"><a class="reference internal" href="doctest.html#directives">Directives</a></li>
  225. <li class="toctree-l3"><a class="reference internal" href="doctest.html#warnings">Warnings</a></li>
  226. </ul>
  227. </li>
  228. <li class="toctree-l2"><a class="reference internal" href="doctest.html#basic-api">Basic API</a></li>
  229. <li class="toctree-l2"><a class="reference internal" href="doctest.html#unittest-api">Unittest API</a></li>
  230. <li class="toctree-l2"><a class="reference internal" href="doctest.html#advanced-api">Advanced API</a><ul>
  231. <li class="toctree-l3"><a class="reference internal" href="doctest.html#doctest-objects">DocTest Objects</a></li>
  232. <li class="toctree-l3"><a class="reference internal" href="doctest.html#example-objects">Example Objects</a></li>
  233. <li class="toctree-l3"><a class="reference internal" href="doctest.html#doctestfinder-objects">DocTestFinder objects</a></li>
  234. <li class="toctree-l3"><a class="reference internal" href="doctest.html#doctestparser-objects">DocTestParser objects</a></li>
  235. <li class="toctree-l3"><a class="reference internal" href="doctest.html#doctestrunner-objects">DocTestRunner objects</a></li>
  236. <li class="toctree-l3"><a class="reference internal" href="doctest.html#outputchecker-objects">OutputChecker objects</a></li>
  237. </ul>
  238. </li>
  239. <li class="toctree-l2"><a class="reference internal" href="doctest.html#debugging">Debugging</a></li>
  240. <li class="toctree-l2"><a class="reference internal" href="doctest.html#soapbox">Soapbox</a></li>
  241. </ul>
  242. </li>
  243. <li class="toctree-l1"><a class="reference internal" href="unittest.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code> — Unit testing framework</a><ul>
  244. <li class="toctree-l2"><a class="reference internal" href="unittest.html#basic-example">Basic example</a></li>
  245. <li class="toctree-l2"><a class="reference internal" href="unittest.html#command-line-interface">Command-Line Interface</a><ul>
  246. <li class="toctree-l3"><a class="reference internal" href="unittest.html#command-line-options">Command-line options</a></li>
  247. </ul>
  248. </li>
  249. <li class="toctree-l2"><a class="reference internal" href="unittest.html#test-discovery">Test Discovery</a></li>
  250. <li class="toctree-l2"><a class="reference internal" href="unittest.html#organizing-test-code">Organizing test code</a></li>
  251. <li class="toctree-l2"><a class="reference internal" href="unittest.html#re-using-old-test-code">Re-using old test code</a></li>
  252. <li class="toctree-l2"><a class="reference internal" href="unittest.html#skipping-tests-and-expected-failures">Skipping tests and expected failures</a></li>
  253. <li class="toctree-l2"><a class="reference internal" href="unittest.html#distinguishing-test-iterations-using-subtests">Distinguishing test iterations using subtests</a></li>
  254. <li class="toctree-l2"><a class="reference internal" href="unittest.html#classes-and-functions">Classes and functions</a><ul>
  255. <li class="toctree-l3"><a class="reference internal" href="unittest.html#test-cases">Test cases</a></li>
  256. <li class="toctree-l3"><a class="reference internal" href="unittest.html#grouping-tests">Grouping tests</a></li>
  257. <li class="toctree-l3"><a class="reference internal" href="unittest.html#loading-and-running-tests">Loading and running tests</a><ul>
  258. <li class="toctree-l4"><a class="reference internal" href="unittest.html#load-tests-protocol">load_tests Protocol</a></li>
  259. </ul>
  260. </li>
  261. </ul>
  262. </li>
  263. <li class="toctree-l2"><a class="reference internal" href="unittest.html#class-and-module-fixtures">Class and Module Fixtures</a><ul>
  264. <li class="toctree-l3"><a class="reference internal" href="unittest.html#setupclass-and-teardownclass">setUpClass and tearDownClass</a></li>
  265. <li class="toctree-l3"><a class="reference internal" href="unittest.html#setupmodule-and-teardownmodule">setUpModule and tearDownModule</a></li>
  266. </ul>
  267. </li>
  268. <li class="toctree-l2"><a class="reference internal" href="unittest.html#signal-handling">Signal Handling</a></li>
  269. </ul>
  270. </li>
  271. <li class="toctree-l1"><a class="reference internal" href="unittest.mock.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest.mock</span></code> — mock object library</a><ul>
  272. <li class="toctree-l2"><a class="reference internal" href="unittest.mock.html#quick-guide">Quick Guide</a></li>
  273. <li class="toctree-l2"><a class="reference internal" href="unittest.mock.html#the-mock-class">The Mock Class</a><ul>
  274. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#calling">Calling</a></li>
  275. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#deleting-attributes">Deleting Attributes</a></li>
  276. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#mock-names-and-the-name-attribute">Mock names and the name attribute</a></li>
  277. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#attaching-mocks-as-attributes">Attaching Mocks as Attributes</a></li>
  278. </ul>
  279. </li>
  280. <li class="toctree-l2"><a class="reference internal" href="unittest.mock.html#the-patchers">The patchers</a><ul>
  281. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#patch">patch</a></li>
  282. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#patch-object">patch.object</a></li>
  283. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#patch-dict">patch.dict</a></li>
  284. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#patch-multiple">patch.multiple</a></li>
  285. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#patch-methods-start-and-stop">patch methods: start and stop</a></li>
  286. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#patch-builtins">patch builtins</a></li>
  287. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#test-prefix">TEST_PREFIX</a></li>
  288. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#nesting-patch-decorators">Nesting Patch Decorators</a></li>
  289. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#where-to-patch">Where to patch</a></li>
  290. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#patching-descriptors-and-proxy-objects">Patching Descriptors and Proxy Objects</a></li>
  291. </ul>
  292. </li>
  293. <li class="toctree-l2"><a class="reference internal" href="unittest.mock.html#magicmock-and-magic-method-support">MagicMock and magic method support</a><ul>
  294. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#mocking-magic-methods">Mocking Magic Methods</a></li>
  295. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#magic-mock">Magic Mock</a></li>
  296. </ul>
  297. </li>
  298. <li class="toctree-l2"><a class="reference internal" href="unittest.mock.html#helpers">Helpers</a><ul>
  299. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#sentinel">sentinel</a></li>
  300. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#default">DEFAULT</a></li>
  301. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#call">call</a></li>
  302. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#create-autospec">create_autospec</a></li>
  303. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#any">ANY</a></li>
  304. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#filter-dir">FILTER_DIR</a></li>
  305. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#mock-open">mock_open</a></li>
  306. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#autospeccing">Autospeccing</a></li>
  307. <li class="toctree-l3"><a class="reference internal" href="unittest.mock.html#sealing-mocks">Sealing mocks</a></li>
  308. </ul>
  309. </li>
  310. <li class="toctree-l2"><a class="reference internal" href="unittest.mock.html#order-of-precedence-of-side-effect-return-value-and-wraps">Order of precedence of <code class="xref py py-attr docutils literal notranslate"><span class="pre">side_effect</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">return_value</span></code> and <em>wraps</em></a></li>
  311. </ul>
  312. </li>
  313. <li class="toctree-l1"><a class="reference internal" href="unittest.mock-examples.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest.mock</span></code> — getting started</a><ul>
  314. <li class="toctree-l2"><a class="reference internal" href="unittest.mock-examples.html#using-mock">Using Mock</a><ul>
  315. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#mock-patching-methods">Mock Patching Methods</a></li>
  316. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#mock-for-method-calls-on-an-object">Mock for Method Calls on an Object</a></li>
  317. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#mocking-classes">Mocking Classes</a></li>
  318. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#naming-your-mocks">Naming your mocks</a></li>
  319. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#tracking-all-calls">Tracking all Calls</a></li>
  320. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#setting-return-values-and-attributes">Setting Return Values and Attributes</a></li>
  321. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#raising-exceptions-with-mocks">Raising exceptions with mocks</a></li>
  322. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#side-effect-functions-and-iterables">Side effect functions and iterables</a></li>
  323. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#mocking-asynchronous-iterators">Mocking asynchronous iterators</a></li>
  324. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#mocking-asynchronous-context-manager">Mocking asynchronous context manager</a></li>
  325. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#creating-a-mock-from-an-existing-object">Creating a Mock from an Existing Object</a></li>
  326. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#using-side-effect-to-return-per-file-content">Using side_effect to return per file content</a></li>
  327. </ul>
  328. </li>
  329. <li class="toctree-l2"><a class="reference internal" href="unittest.mock-examples.html#patch-decorators">Patch Decorators</a></li>
  330. <li class="toctree-l2"><a class="reference internal" href="unittest.mock-examples.html#further-examples">Further Examples</a><ul>
  331. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#mocking-chained-calls">Mocking chained calls</a></li>
  332. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#partial-mocking">Partial mocking</a></li>
  333. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#mocking-a-generator-method">Mocking a Generator Method</a></li>
  334. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#applying-the-same-patch-to-every-test-method">Applying the same patch to every test method</a></li>
  335. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#mocking-unbound-methods">Mocking Unbound Methods</a></li>
  336. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#checking-multiple-calls-with-mock">Checking multiple calls with mock</a></li>
  337. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#coping-with-mutable-arguments">Coping with mutable arguments</a></li>
  338. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#nesting-patches">Nesting Patches</a></li>
  339. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#mocking-a-dictionary-with-magicmock">Mocking a dictionary with MagicMock</a></li>
  340. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#mock-subclasses-and-their-attributes">Mock subclasses and their attributes</a></li>
  341. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#mocking-imports-with-patch-dict">Mocking imports with patch.dict</a></li>
  342. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#tracking-order-of-calls-and-less-verbose-call-assertions">Tracking order of calls and less verbose call assertions</a></li>
  343. <li class="toctree-l3"><a class="reference internal" href="unittest.mock-examples.html#more-complex-argument-matching">More complex argument matching</a></li>
  344. </ul>
  345. </li>
  346. </ul>
  347. </li>
  348. <li class="toctree-l1"><a class="reference internal" href="2to3.html">2to3 — Automated Python 2 to 3 code translation</a><ul>
  349. <li class="toctree-l2"><a class="reference internal" href="2to3.html#using-2to3">Using 2to3</a></li>
  350. <li class="toctree-l2"><a class="reference internal" href="2to3.html#fixers">Fixers</a></li>
  351. <li class="toctree-l2"><a class="reference internal" href="2to3.html#module-lib2to3"><code class="xref py py-mod docutils literal notranslate"><span class="pre">lib2to3</span></code> — 2to3’s library</a></li>
  352. </ul>
  353. </li>
  354. <li class="toctree-l1"><a class="reference internal" href="test.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code> — Regression tests package for Python</a><ul>
  355. <li class="toctree-l2"><a class="reference internal" href="test.html#writing-unit-tests-for-the-test-package">Writing Unit Tests for the <code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code> package</a></li>
  356. <li class="toctree-l2"><a class="reference internal" href="test.html#module-test.regrtest">Running tests using the command-line interface</a></li>
  357. </ul>
  358. </li>
  359. <li class="toctree-l1"><a class="reference internal" href="test.html#module-test.support"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code> — Utilities for the Python test suite</a></li>
  360. <li class="toctree-l1"><a class="reference internal" href="test.html#module-test.support.socket_helper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support.socket_helper</span></code> — Utilities for socket tests</a></li>
  361. <li class="toctree-l1"><a class="reference internal" href="test.html#module-test.support.script_helper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support.script_helper</span></code> — Utilities for the Python execution tests</a></li>
  362. <li class="toctree-l1"><a class="reference internal" href="test.html#module-test.support.bytecode_helper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support.bytecode_helper</span></code> — Support tools for testing correct bytecode generation</a></li>
  363. <li class="toctree-l1"><a class="reference internal" href="test.html#module-test.support.threading_helper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support.threading_helper</span></code> — Utilities for threading tests</a></li>
  364. <li class="toctree-l1"><a class="reference internal" href="test.html#module-test.support.os_helper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support.os_helper</span></code> — Utilities for os tests</a></li>
  365. <li class="toctree-l1"><a class="reference internal" href="test.html#module-test.support.import_helper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support.import_helper</span></code> — Utilities for import tests</a></li>
  366. <li class="toctree-l1"><a class="reference internal" href="test.html#module-test.support.warnings_helper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support.warnings_helper</span></code> — Utilities for warnings tests</a></li>
  367. </ul>
  368. </div>
  369. </section>
  370. <div class="clearer"></div>
  371. </div>
  372. </div>
  373. </div>
  374. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  375. <div class="sphinxsidebarwrapper">
  376. <div>
  377. <h4>Previous topic</h4>
  378. <p class="topless"><a href="idle.html"
  379. title="previous chapter">IDLE</a></p>
  380. </div>
  381. <div>
  382. <h4>Next topic</h4>
  383. <p class="topless"><a href="typing.html"
  384. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code> — Support for type hints</a></p>
  385. </div>
  386. <div role="note" aria-label="source link">
  387. <h3>This Page</h3>
  388. <ul class="this-page-menu">
  389. <li><a href="../bugs.html">Report a Bug</a></li>
  390. <li>
  391. <a href="https://github.com/python/cpython/blob/main/Doc/library/development.rst"
  392. rel="nofollow">Show Source
  393. </a>
  394. </li>
  395. </ul>
  396. </div>
  397. </div>
  398. <div id="sidebarbutton" title="Collapse sidebar">
  399. <span>«</span>
  400. </div>
  401. </div>
  402. <div class="clearer"></div>
  403. </div>
  404. <div class="related" role="navigation" aria-label="related navigation">
  405. <h3>Navigation</h3>
  406. <ul>
  407. <li class="right" style="margin-right: 10px">
  408. <a href="../genindex.html" title="General Index"
  409. >index</a></li>
  410. <li class="right" >
  411. <a href="../py-modindex.html" title="Python Module Index"
  412. >modules</a> |</li>
  413. <li class="right" >
  414. <a href="typing.html" title="typing — Support for type hints"
  415. >next</a> |</li>
  416. <li class="right" >
  417. <a href="idle.html" title="IDLE"
  418. >previous</a> |</li>
  419. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  420. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  421. <li class="switchers">
  422. <div class="language_switcher_placeholder"></div>
  423. <div class="version_switcher_placeholder"></div>
  424. </li>
  425. <li>
  426. </li>
  427. <li id="cpython-language-and-version">
  428. <a href="../index.html">3.12.3 Documentation</a> &#187;
  429. </li>
  430. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  431. <li class="nav-item nav-item-this"><a href="">Development Tools</a></li>
  432. <li class="right">
  433. <div class="inline-search" role="search">
  434. <form class="inline-search" action="../search.html" method="get">
  435. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  436. <input type="submit" value="Go" />
  437. </form>
  438. </div>
  439. |
  440. </li>
  441. <li class="right">
  442. <label class="theme-selector-label">
  443. Theme
  444. <select class="theme-selector" oninput="activateTheme(this.value)">
  445. <option value="auto" selected>Auto</option>
  446. <option value="light">Light</option>
  447. <option value="dark">Dark</option>
  448. </select>
  449. </label> |</li>
  450. </ul>
  451. </div>
  452. <div class="footer">
  453. &copy;
  454. <a href="../copyright.html">
  455. Copyright
  456. </a>
  457. 2001-2024, Python Software Foundation.
  458. <br />
  459. This page is licensed under the Python Software Foundation License Version 2.
  460. <br />
  461. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  462. <br />
  463. See <a href="/license.html">History and License</a> for more information.<br />
  464. <br />
  465. The Python Software Foundation is a non-profit corporation.
  466. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  467. <br />
  468. <br />
  469. Last updated on Apr 09, 2024 (13:47 UTC).
  470. <a href="/bugs.html">Found a bug</a>?
  471. <br />
  472. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  473. </div>
  474. </body>
  475. </html>
上海开阖软件有限公司 沪ICP备12045867号-1