1547 lines
166 KiB
HTML
1547 lines
166 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
|
||
<head>
|
||
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||
|
||
<title>test --- Python 回归测试包 — Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
|
||
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||
<script src="../_static/jquery.js"></script>
|
||
<script src="../_static/underscore.js"></script>
|
||
<script src="../_static/doctools.js"></script>
|
||
<script src="../_static/language_data.js"></script>
|
||
<script src="../_static/translations.js"></script>
|
||
|
||
<script src="../_static/sidebar.js"></script>
|
||
|
||
<link rel="search" type="application/opensearchdescription+xml"
|
||
title="在 Python 3.8.20 文档 中搜索"
|
||
href="../_static/opensearch.xml"/>
|
||
<link rel="author" title="关于这些文档" href="../about.html" />
|
||
<link rel="index" title="索引" href="../genindex.html" />
|
||
<link rel="search" title="搜索" href="../search.html" />
|
||
<link rel="copyright" title="版权所有" href="../copyright.html" />
|
||
<link rel="next" title="调试和分析" href="debug.html" />
|
||
<link rel="prev" title="2to3 - 自动将 Python 2 代码转为 Python 3 代码" href="2to3.html" />
|
||
<link rel="canonical" href="https://docs.python.org/3/library/test.html" />
|
||
|
||
|
||
|
||
|
||
|
||
<style>
|
||
@media only screen {
|
||
table.full-width-table {
|
||
width: 100%;
|
||
}
|
||
}
|
||
</style>
|
||
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
|
||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||
<script type="text/javascript" src="../_static/menu.js"></script>
|
||
|
||
</head>
|
||
<body>
|
||
<div class="mobile-nav">
|
||
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
|
||
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
|
||
<label for="menuToggler" class="toggler__label">
|
||
<span></span>
|
||
</label>
|
||
<nav class="nav-content" role="navigation">
|
||
<a href="https://www.python.org/" class="nav-logo">
|
||
<img src="../_static/py.svg" alt="Logo"/>
|
||
</a>
|
||
<div class="version_switcher_placeholder"></div>
|
||
<form role="search" class="search" action="../search.html" method="get">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
|
||
<path fill-rule="nonzero"
|
||
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" fill="#444"></path>
|
||
</svg>
|
||
<input type="text" name="q" aria-label="快速搜索"/>
|
||
<input type="submit" value="转向"/>
|
||
</form>
|
||
</nav>
|
||
<div class="menu-wrapper">
|
||
<nav class="menu" role="navigation" aria-label="main navigation">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<h3><a href="../contents.html">目录</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code> --- Python 回归测试包</a><ul>
|
||
<li><a class="reference internal" href="#writing-unit-tests-for-the-test-package">为 <code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code> 包编写单元测试</a></li>
|
||
<li><a class="reference internal" href="#running-tests-using-the-command-line-interface">使用命令行界面运行测试</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#module-test.support"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code> --- 针对 Python 测试套件的工具</a></li>
|
||
<li><a class="reference internal" href="#module-test.support.script_helper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support.script_helper</span></code> --- 用于 Python 执行测试工具</a></li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="2to3.html"
|
||
title="上一章">2to3 - 自动将 Python 2 代码转为 Python 3 代码</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="debug.html"
|
||
title="下一章">调试和分析</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>本页</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">报告 Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/3.8/Doc/library/test.rst"
|
||
rel="nofollow">显示源代码
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</nav>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
|
||
这个文档所针对的是一个已不再受支持的 Python 旧版本。
|
||
你应当升级版本,并阅读
|
||
<a href="/3/library/test.html"> Python 当前稳定版本的文档</a>.
|
||
</div>
|
||
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>导航</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="总目录"
|
||
accesskey="I">索引</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python 模块索引"
|
||
>模块</a> |</li>
|
||
<li class="right" >
|
||
<a href="debug.html" title="调试和分析"
|
||
accesskey="N">下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="2to3.html" title="2to3 - 自动将 Python 2 代码转为 Python 3 代码"
|
||
accesskey="P">上一页</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.8.20 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="development.html" accesskey="U">开发工具</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
||
<input type="submit" value="转向" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="module-test">
|
||
<span id="test-regression-tests-package-for-python"></span><h1><a class="reference internal" href="#module-test" title="test: Regression tests package containing the testing suite for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code></a> --- Python 回归测试包<a class="headerlink" href="#module-test" title="永久链接至标题">¶</a></h1>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">注解</p>
|
||
<p><a class="reference internal" href="#module-test" title="test: Regression tests package containing the testing suite for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code></a> 包只供 Python 内部使用。它的记录是为了让 Python 的核心开发者受益。我们不鼓励在 Python 标准库之外使用这个包,因为这里提到的代码在 Python 的不同版本之间可能会改变或被删除而不另行通知。</p>
|
||
</div>
|
||
<hr class="docutils" />
|
||
<p><a class="reference internal" href="#module-test" title="test: Regression tests package containing the testing suite for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code></a> 包包含了 Python 的所有回归测试,以及 <a class="reference internal" href="#module-test.support" title="test.support: Support for Python's regression test suite."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code></a> 和 <code class="xref py py-mod docutils literal notranslate"><span class="pre">test.regrtest</span></code> 模块。 <a class="reference internal" href="#module-test.support" title="test.support: Support for Python's regression test suite."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code></a> 用于增强你的测试,而 <code class="xref py py-mod docutils literal notranslate"><span class="pre">test.regrtest</span></code> 驱动测试套件。</p>
|
||
<p><code class="xref py py-mod docutils literal notranslate"><span class="pre">test`包中每个名字以</span> <span class="pre">``test_`</span></code> 开头的模块都是一个特定模块或功能的测试套件。所有新的测试应该使用 <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> 或 <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> 模块编写。一些旧的测试是使用“传统”的测试风格编写的,即比较打印出来的输出到 <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>;这种测试风格被认为是过时的。</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<dl class="simple">
|
||
<dt>模块 <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></dt><dd><p>编写 PyUnit 回归测试.</p>
|
||
</dd>
|
||
<dt><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> --- 文档测试模块</dt><dd><p>嵌入到文档字符串的测试。</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
<section id="writing-unit-tests-for-the-test-package">
|
||
<span id="writing-tests"></span><h2>为 <a class="reference internal" href="#module-test" title="test: Regression tests package containing the testing suite for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code></a> 包编写单元测试<a class="headerlink" href="#writing-unit-tests-for-the-test-package" title="永久链接至标题">¶</a></h2>
|
||
<p>使用 <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> 模块的测试最好是遵循一些准则。 其中一条是测试模块的名称要以 <code class="docutils literal notranslate"><span class="pre">test_</span></code> 打头并以被测试模块的名称结尾。 测试模块中的测试方法应当以 <code class="docutils literal notranslate"><span class="pre">test_</span></code> 打头并以该方法所测试的内容的说明结尾。 这很有必要因为这样测试驱动程序就会将这些方法识别为测试方法。 此外,该方法不应当包括任何文档字符串。 应当使用注释 (例如 <code class="docutils literal notranslate"><span class="pre">#</span> <span class="pre">Tests</span> <span class="pre">function</span> <span class="pre">returns</span> <span class="pre">only</span> <span class="pre">True</span> <span class="pre">or</span> <span class="pre">False</span></code>) 来为测试方法提供文档说明。 这样做是因为文档字符串如果存在则会被打印出来因此无法指明正在运行哪个测试。</p>
|
||
<p>有一个基本模板经常会被使用:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">unittest</span>
|
||
<span class="kn">from</span> <span class="nn">test</span> <span class="kn">import</span> <span class="n">support</span>
|
||
|
||
<span class="k">class</span> <span class="nc">MyTestCase1</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
|
||
|
||
<span class="c1"># Only use setUp() and tearDown() if necessary</span>
|
||
|
||
<span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="o">...</span> <span class="n">code</span> <span class="n">to</span> <span class="n">execute</span> <span class="ow">in</span> <span class="n">preparation</span> <span class="k">for</span> <span class="n">tests</span> <span class="o">...</span>
|
||
|
||
<span class="k">def</span> <span class="nf">tearDown</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="o">...</span> <span class="n">code</span> <span class="n">to</span> <span class="n">execute</span> <span class="n">to</span> <span class="n">clean</span> <span class="n">up</span> <span class="n">after</span> <span class="n">tests</span> <span class="o">...</span>
|
||
|
||
<span class="k">def</span> <span class="nf">test_feature_one</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="c1"># Test feature one.</span>
|
||
<span class="o">...</span> <span class="n">testing</span> <span class="n">code</span> <span class="o">...</span>
|
||
|
||
<span class="k">def</span> <span class="nf">test_feature_two</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="c1"># Test feature two.</span>
|
||
<span class="o">...</span> <span class="n">testing</span> <span class="n">code</span> <span class="o">...</span>
|
||
|
||
<span class="o">...</span> <span class="n">more</span> <span class="n">test</span> <span class="n">methods</span> <span class="o">...</span>
|
||
|
||
<span class="k">class</span> <span class="nc">MyTestCase2</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
|
||
<span class="o">...</span> <span class="n">same</span> <span class="n">structure</span> <span class="k">as</span> <span class="n">MyTestCase1</span> <span class="o">...</span>
|
||
|
||
<span class="o">...</span> <span class="n">more</span> <span class="n">test</span> <span class="n">classes</span> <span class="o">...</span>
|
||
|
||
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">'__main__'</span><span class="p">:</span>
|
||
<span class="n">unittest</span><span class="o">.</span><span class="n">main</span><span class="p">()</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>这种代码模式允许测试套件由 <code class="xref py py-mod docutils literal notranslate"><span class="pre">test.regrtest</span></code> 运行,作为支持 <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> CLI 的脚本单独运行,或者通过 <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">unittest</span></code> CLI 来运行。</p>
|
||
<p>回归测试的目标是尝试破坏代码。 这引出了一些需要遵循的准则:</p>
|
||
<ul>
|
||
<li><p>测试套件应当测试所有的类、函数和常量。 这不仅包括要向外界展示的外部 API 也包括“私有”的代码。</p></li>
|
||
<li><p>白盒测试(在编写测试时检查被测试的代码)是最推荐的。 黑盒测试(只测试已发布的用户接口)因不够完整而不能确保所有边界和边缘情况都被测试到。</p></li>
|
||
<li><p>确保所有可能的值包括无效的值都被测试到。 这能确保不仅全部的有效值都可被接受而且不适当的值也能被正确地处理。</p></li>
|
||
<li><p>消耗尽可能多的代码路径。 测试发生分支的地方从而调整输入以确保通过代码采取尽可能多的不同路径。</p></li>
|
||
<li><p>为受测试的代码所发现的任何代码缺陷添加明确的测试。 这将确保如果代码在将来被改变错误也不会再次出现。</p></li>
|
||
<li><p>确保在你的测试完成后执行清理(例如关闭并删除所有临时文件)。</p></li>
|
||
<li><p>如果某个测试依赖于操作系统上的特定条件那么要在尝试测试之前先验证该条件是否已存在。</p></li>
|
||
<li><p>尽可能少地导入模块并尽可能快地完成操作。 这可以最大限度地减少测试的外部依赖性并且还可以最大限度地减少导入模块带来的附带影响所导致的异常行为。</p></li>
|
||
<li><p>尝试最大限度地重用代码。 在某些情况下,测试结果会因使用不同类型的输入这样的小细节而变化。 可通过一个指定输入的类来子类化一个基本测试类来最大限度地减少重复代码:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">TestFuncAcceptsSequencesMixin</span><span class="p">:</span>
|
||
|
||
<span class="n">func</span> <span class="o">=</span> <span class="n">mySuperWhammyFunction</span>
|
||
|
||
<span class="k">def</span> <span class="nf">test_func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">arg</span><span class="p">)</span>
|
||
|
||
<span class="k">class</span> <span class="nc">AcceptLists</span><span class="p">(</span><span class="n">TestFuncAcceptsSequencesMixin</span><span class="p">,</span> <span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
|
||
<span class="n">arg</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span>
|
||
|
||
<span class="k">class</span> <span class="nc">AcceptStrings</span><span class="p">(</span><span class="n">TestFuncAcceptsSequencesMixin</span><span class="p">,</span> <span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
|
||
<span class="n">arg</span> <span class="o">=</span> <span class="s1">'abc'</span>
|
||
|
||
<span class="k">class</span> <span class="nc">AcceptTuples</span><span class="p">(</span><span class="n">TestFuncAcceptsSequencesMixin</span><span class="p">,</span> <span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
|
||
<span class="n">arg</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>当使用这种模式时,请记住所有继承自 <a class="reference internal" href="unittest.html#unittest.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.TestCase</span></code></a> 的类都会作为测试来运行。 上面例子中的 <code class="xref py py-class docutils literal notranslate"><span class="pre">Mixin</span></code> 类没有任何数据所以其本身是无法运行的,因此它不是继承自 <a class="reference internal" href="unittest.html#unittest.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.TestCase</span></code></a>。</p>
|
||
</li>
|
||
</ul>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<dl class="simple">
|
||
<dt>测试驱动的开发</dt><dd><p>Kent Beck 所著的阐述在实现代码之前编写驱动的书。</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
<section id="running-tests-using-the-command-line-interface">
|
||
<span id="regrtest"></span><h2>使用命令行界面运行测试<a class="headerlink" href="#running-tests-using-the-command-line-interface" title="永久链接至标题">¶</a></h2>
|
||
<p>通过使用 <a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a> 选项 <a class="reference internal" href="#module-test" title="test: Regression tests package containing the testing suite for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code></a> 包可以作为脚本运行以驱动 Python 的回归测试套件: <strong class="program">python -m test</strong>。 在内部,它使用 <code class="xref py py-mod docutils literal notranslate"><span class="pre">test.regrtest</span></code>;之前 Python 版本所使用的 <strong class="program">python -m test.regrtest</strong> 调用仍然有效。 运行该脚本自身会自动开始运行 <a class="reference internal" href="#module-test" title="test: Regression tests package containing the testing suite for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code></a> 包中的所有回归测试。 它通过在包中查找所有名称以 <code class="docutils literal notranslate"><span class="pre">test_</span></code> 打头的模块,导入它们,并在有 <code class="xref py py-func docutils literal notranslate"><span class="pre">test_main()</span></code> 函数时执行它或是在没有 <code class="docutils literal notranslate"><span class="pre">test_main</span></code> 时通过 unittest.TestLoader.loadTestsFromModule 载入测试。 要执行的测试的名称也可以被传递给脚本。 指定一个单独的回归测试 (<strong class="program">python -m test test_spam</strong>) 将使输出最小化并且只打印测试通过或失败的消息。</p>
|
||
<p>直接运行 <a class="reference internal" href="#module-test" title="test: Regression tests package containing the testing suite for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code></a> 将允许设置哪些资源可供测试使用。 你可以通过使用 <code class="docutils literal notranslate"><span class="pre">-u</span></code> 命令行选项来做到这一点。 指定 <code class="docutils literal notranslate"><span class="pre">all</span></code> 作为 <code class="docutils literal notranslate"><span class="pre">-u</span></code> 选项的值将启用所有可能的资源: <strong class="program">python -m test -uall</strong>。 如果只需要一项资源(这是更为常见的情况),可以在 <code class="docutils literal notranslate"><span class="pre">all</span></code> 之后加一个以逗号分隔的列表来指明不需要的资源。 命令 <strong class="program">python -m test -uall,-audio,-largefile</strong> 将运行 <a class="reference internal" href="#module-test" title="test: Regression tests package containing the testing suite for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code></a> 并使用除 <code class="docutils literal notranslate"><span class="pre">audio</span></code> 和 <code class="docutils literal notranslate"><span class="pre">largefile</span></code> 资源之外的所有资源。 要查看所有资源的列表和更多的命令行选项,请运行 <strong class="program">python -m test -h</strong>。</p>
|
||
<p>另外一些执行回归测试的方式依赖于执行测试所在的系统平台。 在 Unix 上,你可以在构建 Python 的最高层级目录中运行 <strong class="program">make test</strong>。 在 Windows 上,在你的 <code class="file docutils literal notranslate"><span class="pre">PCbuild</span></code> 目录中执行 <strong class="program">rt.bat</strong> 将运行所有的回归测试。</p>
|
||
</section>
|
||
</section>
|
||
<section id="module-test.support">
|
||
<span id="test-support-utilities-for-the-python-test-suite"></span><h1><a class="reference internal" href="#module-test.support" title="test.support: Support for Python's regression test suite."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code></a> --- 针对 Python 测试套件的工具<a class="headerlink" href="#module-test.support" title="永久链接至标题">¶</a></h1>
|
||
<p><a class="reference internal" href="#module-test.support" title="test.support: Support for Python's regression test suite."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code></a> 模块提供了对 Python 的回归测试套件的支持。</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">注解</p>
|
||
<p><a class="reference internal" href="#module-test.support" title="test.support: Support for Python's regression test suite."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code></a> 不是一个公用模块。 这篇文档是为了帮助 Python 开发者编写测试。 此模块的 API 可能被改变而不顾及发行版本之间的向下兼容性问题。</p>
|
||
</div>
|
||
<p>此模块定义了以下异常:</p>
|
||
<dl class="exception">
|
||
<dt id="test.support.TestFailed">
|
||
<em class="property">exception </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TestFailed</code><a class="headerlink" href="#test.support.TestFailed" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>当一个测试失败时将被引发的异常。 此异常已被弃用而应改用基于 <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> 的测试以及 <a class="reference internal" href="unittest.html#unittest.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.TestCase</span></code></a> 的断言方法。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="exception">
|
||
<dt id="test.support.ResourceDenied">
|
||
<em class="property">exception </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">ResourceDenied</code><a class="headerlink" href="#test.support.ResourceDenied" title="永久链接至目标">¶</a></dt>
|
||
<dd><p><a class="reference internal" href="unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-exc docutils literal notranslate"><span class="pre">unittest.SkipTest</span></code></a> 的子类。 当一个资源(例如网络连接)不可用时将被引发。 由 <a class="reference internal" href="#test.support.requires" title="test.support.requires"><code class="xref py py-func docutils literal notranslate"><span class="pre">requires()</span></code></a> 函数所引发。</p>
|
||
</dd></dl>
|
||
|
||
<p><a class="reference internal" href="#module-test.support" title="test.support: Support for Python's regression test suite."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code></a> 模块定义了以下常量:</p>
|
||
<dl class="data">
|
||
<dt id="test.support.verbose">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">verbose</code><a class="headerlink" href="#test.support.verbose" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>当启用详细输出时为 <code class="docutils literal notranslate"><span class="pre">True</span></code>。 当需要有关运行中的测试的更详细信息时应当被选择。 <em>verbose</em> 是由 <code class="xref py py-mod docutils literal notranslate"><span class="pre">test.regrtest</span></code> 来设置的。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.is_jython">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">is_jython</code><a class="headerlink" href="#test.support.is_jython" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果所运行的解释器是 Jython 时为 <code class="docutils literal notranslate"><span class="pre">True</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.is_android">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">is_android</code><a class="headerlink" href="#test.support.is_android" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果系统是 Android 时为 <code class="docutils literal notranslate"><span class="pre">True</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.unix_shell">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">unix_shell</code><a class="headerlink" href="#test.support.unix_shell" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果系统不是 Windows 时则为 shell 的路径;否则为 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.FS_NONASCII">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">FS_NONASCII</code><a class="headerlink" href="#test.support.FS_NONASCII" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个可通过 <a class="reference internal" href="os.html#os.fsencode" title="os.fsencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsencode()</span></code></a> 编码的非 ASCII 字符。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.TESTFN">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TESTFN</code><a class="headerlink" href="#test.support.TESTFN" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>设置为一个可以安全地用作临时文件名的名称。 任何被创建的临时文件都应当被关闭和撤销链接(移除)。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.TESTFN_UNICODE">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TESTFN_UNICODE</code><a class="headerlink" href="#test.support.TESTFN_UNICODE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>设置为用于临时文件的非 ASCII 名称。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.TESTFN_ENCODING">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TESTFN_ENCODING</code><a class="headerlink" href="#test.support.TESTFN_ENCODING" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Set to <a class="reference internal" href="sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.TESTFN_UNENCODABLE">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TESTFN_UNENCODABLE</code><a class="headerlink" href="#test.support.TESTFN_UNENCODABLE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>设置为一个应当在严格模式下不可使用文件系统编码格式来编码的文件名(str 类型)。 如果无法生成这样的文件名则可以为 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.TESTFN_UNDECODABLE">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TESTFN_UNDECODABLE</code><a class="headerlink" href="#test.support.TESTFN_UNDECODABLE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>设置为一个应当在严格模式下不可使用文件系统编码格式来编码的文件名(bytes 类型)。 如果无法生成这样的文件名则可以为 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.TESTFN_NONASCII">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TESTFN_NONASCII</code><a class="headerlink" href="#test.support.TESTFN_NONASCII" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Set to a filename containing the <a class="reference internal" href="#test.support.FS_NONASCII" title="test.support.FS_NONASCII"><code class="xref py py-data docutils literal notranslate"><span class="pre">FS_NONASCII</span></code></a> character.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.IPV6_ENABLED">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">IPV6_ENABLED</code><a class="headerlink" href="#test.support.IPV6_ENABLED" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Set to <code class="docutils literal notranslate"><span class="pre">True</span></code> if IPV6 is enabled on this host, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.SAVEDCWD">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">SAVEDCWD</code><a class="headerlink" href="#test.support.SAVEDCWD" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>设置为 <a class="reference internal" href="os.html#os.getcwd" title="os.getcwd"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.getcwd()</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.PGO">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">PGO</code><a class="headerlink" href="#test.support.PGO" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>当测试对 PGO 没有用处时设置是否要跳过测试。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.PIPE_MAX_SIZE">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">PIPE_MAX_SIZE</code><a class="headerlink" href="#test.support.PIPE_MAX_SIZE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个通常大于下层 OS 管道缓冲区大小的常量,以产生写入阻塞。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.SOCK_MAX_SIZE">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">SOCK_MAX_SIZE</code><a class="headerlink" href="#test.support.SOCK_MAX_SIZE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个通常大于下层 OS 套接字缓冲区大小的常量,以产生写入阻塞。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.TEST_SUPPORT_DIR">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TEST_SUPPORT_DIR</code><a class="headerlink" href="#test.support.TEST_SUPPORT_DIR" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>设为包含 <a class="reference internal" href="#module-test.support" title="test.support: Support for Python's regression test suite."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code></a> 的最高层级目录。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.TEST_HOME_DIR">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TEST_HOME_DIR</code><a class="headerlink" href="#test.support.TEST_HOME_DIR" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>设为 test 包的最高层级目录。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.TEST_DATA_DIR">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TEST_DATA_DIR</code><a class="headerlink" href="#test.support.TEST_DATA_DIR" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>设为 test 包中的 <code class="docutils literal notranslate"><span class="pre">data</span></code> 目录。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.MAX_Py_ssize_t">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">MAX_Py_ssize_t</code><a class="headerlink" href="#test.support.MAX_Py_ssize_t" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>设为大内存测试的 <a class="reference internal" href="sys.html#sys.maxsize" title="sys.maxsize"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.maxsize</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.max_memuse">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">max_memuse</code><a class="headerlink" href="#test.support.max_memuse" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>通过 <a class="reference internal" href="#test.support.set_memlimit" title="test.support.set_memlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_memlimit()</span></code></a> 设为针对大内存测试的内存限制。 受 <a class="reference internal" href="#test.support.MAX_Py_ssize_t" title="test.support.MAX_Py_ssize_t"><code class="xref py py-data docutils literal notranslate"><span class="pre">MAX_Py_ssize_t</span></code></a> 的限制。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.real_max_memuse">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">real_max_memuse</code><a class="headerlink" href="#test.support.real_max_memuse" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>通过 <a class="reference internal" href="#test.support.set_memlimit" title="test.support.set_memlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_memlimit()</span></code></a> 设为针对大内存测试的内存限制。 不受 <a class="reference internal" href="#test.support.MAX_Py_ssize_t" title="test.support.MAX_Py_ssize_t"><code class="xref py py-data docutils literal notranslate"><span class="pre">MAX_Py_ssize_t</span></code></a> 的限制。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.MISSING_C_DOCSTRINGS">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">MISSING_C_DOCSTRINGS</code><a class="headerlink" href="#test.support.MISSING_C_DOCSTRINGS" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if running on CPython, not on Windows, and configuration
|
||
not set with <code class="docutils literal notranslate"><span class="pre">WITH_DOC_STRINGS</span></code>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.HAVE_DOCSTRINGS">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">HAVE_DOCSTRINGS</code><a class="headerlink" href="#test.support.HAVE_DOCSTRINGS" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Check for presence of docstrings.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.TEST_HTTP_URL">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TEST_HTTP_URL</code><a class="headerlink" href="#test.support.TEST_HTTP_URL" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>定义用于网络测试的韧性 HTTP 服务器的 URL。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.ALWAYS_EQ">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">ALWAYS_EQ</code><a class="headerlink" href="#test.support.ALWAYS_EQ" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>等于任何对象的对象。 用于测试混合类型比较。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.LARGEST">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">LARGEST</code><a class="headerlink" href="#test.support.LARGEST" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>大于任何对象的对象(除了其自身)。 用于测试混合类型比较。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="test.support.SMALLEST">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">SMALLEST</code><a class="headerlink" href="#test.support.SMALLEST" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>小于任何对象的对象(除了其自身)。 用于测试混合类型比较。Used to test mixed type comparison.</p>
|
||
</dd></dl>
|
||
|
||
<p><a class="reference internal" href="#module-test.support" title="test.support: Support for Python's regression test suite."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code></a> 模块定义了以下函数:</p>
|
||
<dl class="function">
|
||
<dt id="test.support.forget">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">forget</code><span class="sig-paren">(</span><em class="sig-param">module_name</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.forget" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>从 <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> 移除名为 <em>module_name</em> 的模块并删除该模块的已编译字节码文件。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.unload">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">unload</code><span class="sig-paren">(</span><em class="sig-param">name</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.unload" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>从 <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> 中删除 <em>name</em>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.unlink">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">unlink</code><span class="sig-paren">(</span><em class="sig-param">filename</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.unlink" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Call <a class="reference internal" href="os.html#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.unlink()</span></code></a> on <em>filename</em>. On Windows platforms, this is
|
||
wrapped with a wait loop that checks for the existence fo the file.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.rmdir">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">rmdir</code><span class="sig-paren">(</span><em class="sig-param">filename</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.rmdir" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Call <a class="reference internal" href="os.html#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.rmdir()</span></code></a> on <em>filename</em>. On Windows platforms, this is
|
||
wrapped with a wait loop that checks for the existence of the file.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.rmtree">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">rmtree</code><span class="sig-paren">(</span><em class="sig-param">path</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.rmtree" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Call <a class="reference internal" href="shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.rmtree()</span></code></a> on <em>path</em> or call <a class="reference internal" href="os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.lstat()</span></code></a> and
|
||
<a class="reference internal" href="os.html#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.rmdir()</span></code></a> to remove a path and its contents. On Windows platforms,
|
||
this is wrapped with a wait loop that checks for the existence of the files.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.make_legacy_pyc">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">make_legacy_pyc</code><span class="sig-paren">(</span><em class="sig-param">source</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.make_legacy_pyc" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将 <span class="target" id="index-10"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3147"><strong>PEP 3147</strong></a>/<span class="target" id="index-11"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0488"><strong>PEP 488</strong></a> pyc 文件移至旧版 pyc 位置并返回该旧版 pyc 文件的文件系统路径。 <em>source</em> 的值是源文件的文件系统路径。 它不必真实存在,但是 PEP 3147/488 pyc 文件必须存在。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.is_resource_enabled">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">is_resource_enabled</code><span class="sig-paren">(</span><em class="sig-param">resource</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.is_resource_enabled" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果 <em>resource</em> 已启用并可用则返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>。 可用资源列表只有当 <code class="xref py py-mod docutils literal notranslate"><span class="pre">test.regrtest</span></code> 正在执行测试时才会被设置。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.python_is_optimized">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">python_is_optimized</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.python_is_optimized" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果 Python 编译未使用 <code class="docutils literal notranslate"><span class="pre">-O0</span></code> 或 <code class="docutils literal notranslate"><span class="pre">-Og</span></code> 则返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.with_pymalloc">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">with_pymalloc</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.with_pymalloc" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回 <code class="xref py py-data docutils literal notranslate"><span class="pre">_testcapi.WITH_PYMALLOC</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.requires">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">requires</code><span class="sig-paren">(</span><em class="sig-param">resource</em>, <em class="sig-param">msg=None</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.requires" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果 <em>resource</em> 不可用则引发 <a class="reference internal" href="#test.support.ResourceDenied" title="test.support.ResourceDenied"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceDenied</span></code></a>。 如果该异常被引发则 <em>msg</em> 为传给 <a class="reference internal" href="#test.support.ResourceDenied" title="test.support.ResourceDenied"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceDenied</span></code></a> 的参数。 如果被 <code class="docutils literal notranslate"><span class="pre">__name__</span></code> 为 <code class="docutils literal notranslate"><span class="pre">'__main__'</span></code> 的函数调用则总是返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>。 在测试由 <code class="xref py py-mod docutils literal notranslate"><span class="pre">test.regrtest</span></code> 执行时使用。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.system_must_validate_cert">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">system_must_validate_cert</code><span class="sig-paren">(</span><em class="sig-param">f</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.system_must_validate_cert" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Raise <a class="reference internal" href="unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-exc docutils literal notranslate"><span class="pre">unittest.SkipTest</span></code></a> on TLS certification validation failures.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.sortdict">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">sortdict</code><span class="sig-paren">(</span><em class="sig-param">dict</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.sortdict" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回 <em>dict</em> 按键排序的 repr。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.findfile">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">findfile</code><span class="sig-paren">(</span><em class="sig-param">filename</em>, <em class="sig-param">subdir=None</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.findfile" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回名为 <em>filename</em> 的文件的路径。 如果未找到匹配结果则返回 <em>filename</em>。 这并不等于失败因为它也算是该文件的路径。</p>
|
||
<p>设置 <em>subdir</em> 指明要用来查找文件的相对路径而不是直接在路径目录中查找。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.create_empty_file">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">create_empty_file</code><span class="sig-paren">(</span><em class="sig-param">filename</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.create_empty_file" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>创建一个名为 <em>filename</em> 的空文件。 如果文件已存在,则清空其内容。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.fd_count">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">fd_count</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.fd_count" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>统计打开的文件描述符数量。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.match_test">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">match_test</code><span class="sig-paren">(</span><em class="sig-param">test</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.match_test" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Match <em>test</em> to patterns set in <a class="reference internal" href="#test.support.set_match_tests" title="test.support.set_match_tests"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_match_tests()</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.set_match_tests">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">set_match_tests</code><span class="sig-paren">(</span><em class="sig-param">patterns</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.set_match_tests" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Define match test with regular expression <em>patterns</em>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.run_unittest">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">run_unittest</code><span class="sig-paren">(</span><em class="sig-param">*classes</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.run_unittest" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>执行传给函数的 <a class="reference internal" href="unittest.html#unittest.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.TestCase</span></code></a> 子类。 此函数会扫描类中带有 <code class="docutils literal notranslate"><span class="pre">test_</span></code> 前缀的方法并单独执行这些测试。</p>
|
||
<p>将字符串作为形参传递也是合法的;这些形参应为 <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> 中的键。 每个被关联的模块将由 <code class="docutils literal notranslate"><span class="pre">unittest.TestLoader.loadTestsFromModule()</span></code> 执行扫描。 这通常出现在以下 <code class="xref py py-func docutils literal notranslate"><span class="pre">test_main()</span></code> 函数中:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">test_main</span><span class="p">():</span>
|
||
<span class="n">support</span><span class="o">.</span><span class="n">run_unittest</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>这将运行在指定模块中定义的所有测试。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.run_doctest">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">run_doctest</code><span class="sig-paren">(</span><em class="sig-param">module</em>, <em class="sig-param">verbosity=None</em>, <em class="sig-param">optionflags=0</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.run_doctest" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>在给定的 <em>module</em> 上运行 <a class="reference internal" href="doctest.html#doctest.testmod" title="doctest.testmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">doctest.testmod()</span></code></a>。 返回 <code class="docutils literal notranslate"><span class="pre">(failure_count,</span> <span class="pre">test_count)</span></code>。</p>
|
||
<p>如果 <em>verbosity</em> 为 <code class="docutils literal notranslate"><span class="pre">None</span></code>,<a class="reference internal" href="doctest.html#doctest.testmod" title="doctest.testmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">doctest.testmod()</span></code></a> 运行时的消息详细程度将设为 <a class="reference internal" href="#test.support.verbose" title="test.support.verbose"><code class="xref py py-data docutils literal notranslate"><span class="pre">verbose</span></code></a>。 否则,运行时的消息详细程度将设为 <code class="docutils literal notranslate"><span class="pre">None</span></code>。 <em>optionflags</em> 将作为 <code class="docutils literal notranslate"><span class="pre">optionflags</span></code> 传给 <a class="reference internal" href="doctest.html#doctest.testmod" title="doctest.testmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">doctest.testmod()</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.setswitchinterval">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">setswitchinterval</code><span class="sig-paren">(</span><em class="sig-param">interval</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.setswitchinterval" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将 <a class="reference internal" href="sys.html#sys.setswitchinterval" title="sys.setswitchinterval"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.setswitchinterval()</span></code></a> 设为给定的 <em>interval</em>。 请为 Android 系统定义一个最小间隔以防止系统挂起。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.check_impl_detail">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">check_impl_detail</code><span class="sig-paren">(</span><em class="sig-param">**guards</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.check_impl_detail" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Use this check to guard CPython's implementation-specific tests or to
|
||
run them only on the implementations guarded by the arguments:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">check_impl_detail</span><span class="p">()</span> <span class="c1"># Only on CPython (default).</span>
|
||
<span class="n">check_impl_detail</span><span class="p">(</span><span class="n">jython</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="c1"># Only on Jython.</span>
|
||
<span class="n">check_impl_detail</span><span class="p">(</span><span class="n">cpython</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> <span class="c1"># Everywhere except CPython.</span>
|
||
</pre></div>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.check_warnings">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">check_warnings</code><span class="sig-paren">(</span><em class="sig-param">*filters</em>, <em class="sig-param">quiet=True</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.check_warnings" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个用于 <a class="reference internal" href="warnings.html#warnings.catch_warnings" title="warnings.catch_warnings"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.catch_warnings()</span></code></a> 以更容易地测试特定警告是否被正确引发的便捷包装器。 它大致等价于调用 <code class="docutils literal notranslate"><span class="pre">warnings.catch_warnings(record=True)</span></code> 并将 <a class="reference internal" href="warnings.html#warnings.simplefilter" title="warnings.simplefilter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">warnings.simplefilter()</span></code></a> 设为 <code class="docutils literal notranslate"><span class="pre">always</span></code> 并附带自动验证已记录结果的选项。</p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">check_warnings</span></code> 接受 <code class="docutils literal notranslate"><span class="pre">("message</span> <span class="pre">regexp",</span> <span class="pre">WarningCategory)</span></code> 形式的 2 元组作为位置参数。 如果提供了一个或多个 <em>filters</em>,或者如果可选的关键字参数 <em>quiet</em> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code>,则它会检查确认警告是符合预期的:每个已指定的过滤器必须匹配至少一个被包围的代码或测试失败时引发的警告,并且如果有任何未能匹配已指定过滤器的警告被引发则测试将失败。 要禁用这些检查中的第一项,请将 <em>quiet</em> 设为 <code class="docutils literal notranslate"><span class="pre">True</span></code>。</p>
|
||
<p>如果未指定任何参数,则默认为:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">check_warnings</span><span class="p">((</span><span class="s2">""</span><span class="p">,</span> <span class="ne">Warning</span><span class="p">),</span> <span class="n">quiet</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>在此情况下所有警告都会被捕获而不会引发任何错误。</p>
|
||
<p>在进入该上下文管理器时,将返回一个 <code class="xref py py-class docutils literal notranslate"><span class="pre">WarningRecorder</span></code> 实例。 来自 <a class="reference internal" href="warnings.html#warnings.catch_warnings" title="warnings.catch_warnings"><code class="xref py py-func docutils literal notranslate"><span class="pre">catch_warnings()</span></code></a> 的下层警告列表可通过该记录器对象的 <a class="reference internal" href="warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-attr docutils literal notranslate"><span class="pre">warnings</span></code></a> 属性来访问。 作为一个便捷方式,该对象中代表最近的警告的属性也可通过该记录器对象来直接访问(参见以下示例)。 如果未引发任何警告,则在其他情况下预期代表一个警告的任何对象属性都将返回 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p>
|
||
<p>该记录器对象还有一个 <code class="xref py py-meth docutils literal notranslate"><span class="pre">reset()</span></code> 方法,该方法会清空警告列表。</p>
|
||
<p>该上下文管理器被设计为像这样来使用:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">check_warnings</span><span class="p">((</span><span class="s2">"assertion is always true"</span><span class="p">,</span> <span class="ne">SyntaxWarning</span><span class="p">),</span>
|
||
<span class="p">(</span><span class="s2">""</span><span class="p">,</span> <span class="ne">UserWarning</span><span class="p">)):</span>
|
||
<span class="n">exec</span><span class="p">(</span><span class="s1">'assert(False, "Hey!")'</span><span class="p">)</span>
|
||
<span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="ne">UserWarning</span><span class="p">(</span><span class="s2">"Hide me!"</span><span class="p">))</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>在此情况下如果两个警告都未被引发,或是引发了其他的警告,则 <a class="reference internal" href="#test.support.check_warnings" title="test.support.check_warnings"><code class="xref py py-func docutils literal notranslate"><span class="pre">check_warnings()</span></code></a> 将会引发一个错误。</p>
|
||
<p>当一个测试需要更深入地查看这些警告,而不是仅仅检查它们是否发生时,可以使用这样的代码:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">check_warnings</span><span class="p">(</span><span class="n">quiet</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="k">as</span> <span class="n">w</span><span class="p">:</span>
|
||
<span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
|
||
<span class="k">assert</span> <span class="nb">str</span><span class="p">(</span><span class="n">w</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="s2">"foo"</span>
|
||
<span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">"bar"</span><span class="p">)</span>
|
||
<span class="k">assert</span> <span class="nb">str</span><span class="p">(</span><span class="n">w</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="s2">"bar"</span>
|
||
<span class="k">assert</span> <span class="nb">str</span><span class="p">(</span><span class="n">w</span><span class="o">.</span><span class="n">warnings</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="s2">"foo"</span>
|
||
<span class="k">assert</span> <span class="nb">str</span><span class="p">(</span><span class="n">w</span><span class="o">.</span><span class="n">warnings</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="s2">"bar"</span>
|
||
<span class="n">w</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
|
||
<span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">w</span><span class="o">.</span><span class="n">warnings</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>在这里所有的警告都将被捕获,而测试代码会直接测试被捕获的警告。</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.2 版更改: </span>新增可选参数 <em>filters</em> 和 <em>quiet</em>。</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.check_no_resource_warning">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">check_no_resource_warning</code><span class="sig-paren">(</span><em class="sig-param">testcase</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.check_no_resource_warning" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>检测是否没有任何 <a class="reference internal" href="exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a> 被引发的上下文管理器。 你必须在该上下文管理器结束之前移除可能发出 <a class="reference internal" href="exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a> 的对象。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.set_memlimit">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">set_memlimit</code><span class="sig-paren">(</span><em class="sig-param">limit</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.set_memlimit" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>针对大内存测试设置 <a class="reference internal" href="#test.support.max_memuse" title="test.support.max_memuse"><code class="xref py py-data docutils literal notranslate"><span class="pre">max_memuse</span></code></a> 和 <a class="reference internal" href="#test.support.real_max_memuse" title="test.support.real_max_memuse"><code class="xref py py-data docutils literal notranslate"><span class="pre">real_max_memuse</span></code></a> 的值。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.record_original_stdout">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">record_original_stdout</code><span class="sig-paren">(</span><em class="sig-param">stdout</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.record_original_stdout" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>存放来自 <em>stdout</em> 的值。 它会在回归测试开始时处理 stdout。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.get_original_stdout">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">get_original_stdout</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.get_original_stdout" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回 <a class="reference internal" href="#test.support.record_original_stdout" title="test.support.record_original_stdout"><code class="xref py py-func docutils literal notranslate"><span class="pre">record_original_stdout()</span></code></a> 所设置的原始 stdout 或者如果未设置则为 <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.strip_python_strerr">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">strip_python_strerr</code><span class="sig-paren">(</span><em class="sig-param">stderr</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.strip_python_strerr" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Strip the <em>stderr</em> of a Python process from potential debug output
|
||
emitted by the interpreter. This will typically be run on the result of
|
||
<a class="reference internal" href="subprocess.html#subprocess.Popen.communicate" title="subprocess.Popen.communicate"><code class="xref py py-meth docutils literal notranslate"><span class="pre">subprocess.Popen.communicate()</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.args_from_interpreter_flags">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">args_from_interpreter_flags</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.args_from_interpreter_flags" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回在 <code class="docutils literal notranslate"><span class="pre">sys.flags</span></code> 和 <code class="docutils literal notranslate"><span class="pre">sys.warnoptions</span></code> 中重新产生当前设置的命令行参数列表。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.optim_args_from_interpreter_flags">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">optim_args_from_interpreter_flags</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.optim_args_from_interpreter_flags" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回在 <code class="docutils literal notranslate"><span class="pre">sys.flags</span></code> 中重新产生当前优化设置的命令行参数列表。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.captured_stdin">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">captured_stdin</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.captured_stdin" title="永久链接至目标">¶</a></dt>
|
||
<dt id="test.support.captured_stdout">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">captured_stdout</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.captured_stdout" title="永久链接至目标">¶</a></dt>
|
||
<dt id="test.support.captured_stderr">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">captured_stderr</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.captured_stderr" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>使用 <a class="reference internal" href="io.html#io.StringIO" title="io.StringIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.StringIO</span></code></a> 对象临时替换指定流的上下文管理器。</p>
|
||
<p>使用输出流的示例:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">captured_stdout</span><span class="p">()</span> <span class="k">as</span> <span class="n">stdout</span><span class="p">,</span> <span class="n">captured_stderr</span><span class="p">()</span> <span class="k">as</span> <span class="n">stderr</span><span class="p">:</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">)</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="s2">"error"</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="p">)</span>
|
||
<span class="k">assert</span> <span class="n">stdout</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span> <span class="o">==</span> <span class="s2">"hello</span><span class="se">\n</span><span class="s2">"</span>
|
||
<span class="k">assert</span> <span class="n">stderr</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span> <span class="o">==</span> <span class="s2">"error</span><span class="se">\n</span><span class="s2">"</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>使用输入流的示例:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">captured_stdin</span><span class="p">()</span> <span class="k">as</span> <span class="n">stdin</span><span class="p">:</span>
|
||
<span class="n">stdin</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'hello</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
||
<span class="n">stdin</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||
<span class="c1"># call test code that consumes from sys.stdin</span>
|
||
<span class="n">captured</span> <span class="o">=</span> <span class="nb">input</span><span class="p">()</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="n">captured</span><span class="p">,</span> <span class="s2">"hello"</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.temp_dir">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">temp_dir</code><span class="sig-paren">(</span><em class="sig-param">path=None</em>, <em class="sig-param">quiet=False</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.temp_dir" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个在 <em>path</em> 上创建临时目录并输出该目录的上下文管理器。</p>
|
||
<p>如果 <em>path</em> 为 <code class="docutils literal notranslate"><span class="pre">None</span></code>,则会使用 <a class="reference internal" href="tempfile.html#tempfile.mkdtemp" title="tempfile.mkdtemp"><code class="xref py py-func docutils literal notranslate"><span class="pre">tempfile.mkdtemp()</span></code></a> 来创建临时目录。 如果 <em>quiet</em> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code>,则该上下文管理器在发生错误时会引发一个异常。 在其他情况下,如果 <em>path</em> 已被指定并且无法创建,则只会发出一个警告。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.change_cwd">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">change_cwd</code><span class="sig-paren">(</span><em class="sig-param">path</em>, <em class="sig-param">quiet=False</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.change_cwd" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个临时性地将当前工作目录改为 <em>path</em> 并输出该目录的上下文管理器。</p>
|
||
<p>如果 <em>quiet</em> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code>,此上下文管理器将在发生错误时引发一个异常。 在其他情况下,它将只发出一个警告并将当前工作目录保持原状。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.temp_cwd">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">temp_cwd</code><span class="sig-paren">(</span><em class="sig-param">name='tempcwd'</em>, <em class="sig-param">quiet=False</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.temp_cwd" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个临时性地创建新目录并改变当前工作目录(CWD)的上下文管理器。</p>
|
||
<p>临时性地改变当前工作目录之前此上下文管理器会在当前目录下创建一个名为 <em>name</em> 的临时目录。 如果 <em>name</em> 为 <code class="docutils literal notranslate"><span class="pre">None</span></code>,则会使用 <a class="reference internal" href="tempfile.html#tempfile.mkdtemp" title="tempfile.mkdtemp"><code class="xref py py-func docutils literal notranslate"><span class="pre">tempfile.mkdtemp()</span></code></a> 创建临时目录。</p>
|
||
<p>如果 <em>quiet</em> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code> 并且无法创建或修改 CWD,则会引发一个错误。 在其他情况下,只会引发一个警告并使用原始 CWD。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.temp_umask">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">temp_umask</code><span class="sig-paren">(</span><em class="sig-param">umask</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.temp_umask" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个临时性地设置进程掩码的上下文管理器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.transient_internet">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">transient_internet</code><span class="sig-paren">(</span><em class="sig-param">resource_name</em>, <em class="sig-param">*</em>, <em class="sig-param">timeout=30.0</em>, <em class="sig-param">errnos=()</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.transient_internet" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>A context manager that raises <a class="reference internal" href="#test.support.ResourceDenied" title="test.support.ResourceDenied"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceDenied</span></code></a> when various issues
|
||
with the internet connection manifest themselves as exceptions.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.disable_faulthandler">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">disable_faulthandler</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.disable_faulthandler" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>A context manager that replaces <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> with <code class="docutils literal notranslate"><span class="pre">sys.__stderr__</span></code>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.gc_collect">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">gc_collect</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.gc_collect" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>强制收集尽可能多的对象。 这是有必要的因为垃圾回收器并不能保证及时回收资源。 这意味着 <code class="docutils literal notranslate"><span class="pre">__del__</span></code> 方法的调用可能会晚于预期而弱引用的存活长于预期。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.disable_gc">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">disable_gc</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.disable_gc" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>A context manager that disables the garbage collector upon entry and
|
||
reenables it upon exit.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.swap_attr">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">swap_attr</code><span class="sig-paren">(</span><em class="sig-param">obj</em>, <em class="sig-param">attr</em>, <em class="sig-param">new_val</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.swap_attr" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>上下文管理器用一个新对象来交换一个属性。</p>
|
||
<p>用法:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">swap_attr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s2">"attr"</span><span class="p">,</span> <span class="mi">5</span><span class="p">):</span>
|
||
<span class="o">...</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>这将把 <code class="docutils literal notranslate"><span class="pre">obj.attr</span></code> 设为 5 并在 <code class="docutils literal notranslate"><span class="pre">with</span></code> 语句块内保持,在语句块结束时恢复旧值。 如果 <code class="docutils literal notranslate"><span class="pre">attr</span></code> 不存在于 <code class="docutils literal notranslate"><span class="pre">obj</span></code> 中,它将被创建并在语句块结束时被删除。</p>
|
||
<p>旧值 (或者如果不存在旧值则为 <code class="docutils literal notranslate"><span class="pre">None</span></code>) 将被赋给 "as" 子句的目标,如果存在子句的话。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.swap_item">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">swap_item</code><span class="sig-paren">(</span><em class="sig-param">obj</em>, <em class="sig-param">attr</em>, <em class="sig-param">new_val</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.swap_item" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>上下文件管理器用一个新对象来交换一个条目。</p>
|
||
<p>用法:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">swap_item</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s2">"item"</span><span class="p">,</span> <span class="mi">5</span><span class="p">):</span>
|
||
<span class="o">...</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>这将把 <code class="docutils literal notranslate"><span class="pre">obj["item"]</span></code> 设为 5 并在 <code class="docutils literal notranslate"><span class="pre">with</span></code> 语句块内保持,在语句块结束时恢复旧值。 如果 <code class="docutils literal notranslate"><span class="pre">item</span></code> 不存在于 <code class="docutils literal notranslate"><span class="pre">obj</span></code> 中,它将被创建并在语句块结束时被删除。</p>
|
||
<p>旧值 (或者如果不存在旧值则为 <code class="docutils literal notranslate"><span class="pre">None</span></code>) 将被赋给 "as" 子句的目标,如果存在子句的话。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.wait_threads_exit">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">wait_threads_exit</code><span class="sig-paren">(</span><em class="sig-param">timeout=60.0</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.wait_threads_exit" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>等待直到 <code class="docutils literal notranslate"><span class="pre">with</span></code> 语句中所有已创建线程退出的上下文管理器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.start_threads">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">start_threads</code><span class="sig-paren">(</span><em class="sig-param">threads</em>, <em class="sig-param">unlock=None</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.start_threads" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Context manager to start <em>threads</em>. It attempts to join the threads upon
|
||
exit.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.calcobjsize">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">calcobjsize</code><span class="sig-paren">(</span><em class="sig-param">fmt</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.calcobjsize" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Return <a class="reference internal" href="struct.html#struct.calcsize" title="struct.calcsize"><code class="xref py py-func docutils literal notranslate"><span class="pre">struct.calcsize()</span></code></a> for <code class="docutils literal notranslate"><span class="pre">nP{fmt}0n</span></code> or, if <code class="docutils literal notranslate"><span class="pre">gettotalrefcount</span></code>
|
||
exists, <code class="docutils literal notranslate"><span class="pre">2PnP{fmt}0P</span></code>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.calcvobjsize">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">calcvobjsize</code><span class="sig-paren">(</span><em class="sig-param">fmt</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.calcvobjsize" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Return <a class="reference internal" href="struct.html#struct.calcsize" title="struct.calcsize"><code class="xref py py-func docutils literal notranslate"><span class="pre">struct.calcsize()</span></code></a> for <code class="docutils literal notranslate"><span class="pre">nPn{fmt}0n</span></code> or, if <code class="docutils literal notranslate"><span class="pre">gettotalrefcount</span></code>
|
||
exists, <code class="docutils literal notranslate"><span class="pre">2PnPn{fmt}0P</span></code>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.checksizeof">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">checksizeof</code><span class="sig-paren">(</span><em class="sig-param">test</em>, <em class="sig-param">o</em>, <em class="sig-param">size</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.checksizeof" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>对于测试用例 <em>test</em>,断言 <em>o</em> 的 <code class="docutils literal notranslate"><span class="pre">sys.getsizeof</span></code> 加 GC 头的大小等于 <em>size</em>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.can_symlink">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">can_symlink</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.can_symlink" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果操作系统支持符号链接则返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>,否则返回 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.can_xattr">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">can_xattr</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.can_xattr" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果操作系统支持 xattr 支返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>,否则返回 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.skip_unless_symlink">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">skip_unless_symlink</code><a class="headerlink" href="#test.support.skip_unless_symlink" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个用于运行需要符号链接支持的测试的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.skip_unless_xattr">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">skip_unless_xattr</code><a class="headerlink" href="#test.support.skip_unless_xattr" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个用于运行需要 xattr 支持的测试的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.skip_unless_bind_unix_socket">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">skip_unless_bind_unix_socket</code><a class="headerlink" href="#test.support.skip_unless_bind_unix_socket" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>A decorator for running tests that require a functional bind() for Unix
|
||
sockets.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.anticipate_failure">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">anticipate_failure</code><span class="sig-paren">(</span><em class="sig-param">condition</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.anticipate_failure" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个有条件地用 <a class="reference internal" href="unittest.html#unittest.expectedFailure" title="unittest.expectedFailure"><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.expectedFailure()</span></code></a> 来标记测试的装饰器。 任何对此装饰器的使用都应当具有标识相应追踪事项的有关联注释。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.run_with_locale">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">run_with_locale</code><span class="sig-paren">(</span><em class="sig-param">catstr</em>, <em class="sig-param">*locales</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.run_with_locale" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个在不同语言区域下运行函数的装饰器,并在其结束后正确地重置语言区域。 <em>catstr</em> 是字符串形式的语言区域类别 (例如 <code class="docutils literal notranslate"><span class="pre">"LC_ALL"</span></code>)。 传入的 <em>locales</em> 将依次被尝试,并将使用第一个有效的语言区域。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.run_with_tz">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">run_with_tz</code><span class="sig-paren">(</span><em class="sig-param">tz</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.run_with_tz" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个在指定时区下运行函数的装饰器,并在其结束后正确地重置时区。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.requires_freebsd_version">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">requires_freebsd_version</code><span class="sig-paren">(</span><em class="sig-param">*min_version</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.requires_freebsd_version" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Decorator for the minimum version when running test on FreeBSD. If the
|
||
FreeBSD version is less than the minimum, raise <a class="reference internal" href="unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-exc docutils literal notranslate"><span class="pre">unittest.SkipTest</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.requires_linux_version">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">requires_linux_version</code><span class="sig-paren">(</span><em class="sig-param">*min_version</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.requires_linux_version" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Decorator for the minimum version when running test on Linux. If the
|
||
Linux version is less than the minimum, raise <a class="reference internal" href="unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-exc docutils literal notranslate"><span class="pre">unittest.SkipTest</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.requires_mac_version">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">requires_mac_version</code><span class="sig-paren">(</span><em class="sig-param">*min_version</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.requires_mac_version" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Decorator for the minimum version when running test on Mac OS X. If the
|
||
MAC OS X version is less than the minimum, raise <a class="reference internal" href="unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-exc docutils literal notranslate"><span class="pre">unittest.SkipTest</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.requires_IEEE_754">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">requires_IEEE_754</code><a class="headerlink" href="#test.support.requires_IEEE_754" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于在非 non-IEEE 754 平台上跳过测试的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.requires_zlib">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">requires_zlib</code><a class="headerlink" href="#test.support.requires_zlib" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于当 <a class="reference internal" href="zlib.html#module-zlib" title="zlib: Low-level interface to compression and decompression routines compatible with gzip."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zlib</span></code></a> 不存在时跳过测试的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.requires_gzip">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">requires_gzip</code><a class="headerlink" href="#test.support.requires_gzip" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于当 <a class="reference internal" href="gzip.html#module-gzip" title="gzip: Interfaces for gzip compression and decompression using file objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gzip</span></code></a> 不存在时跳过测试的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.requires_bz2">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">requires_bz2</code><a class="headerlink" href="#test.support.requires_bz2" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于当 <a class="reference internal" href="bz2.html#module-bz2" title="bz2: Interfaces for bzip2 compression and decompression."><code class="xref py py-mod docutils literal notranslate"><span class="pre">bz2</span></code></a> 不存在时跳过测试的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.requires_lzma">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">requires_lzma</code><a class="headerlink" href="#test.support.requires_lzma" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于当 <a class="reference internal" href="lzma.html#module-lzma" title="lzma: A Python wrapper for the liblzma compression library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">lzma</span></code></a> 不存在时跳过测试的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.requires_resource">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">requires_resource</code><span class="sig-paren">(</span><em class="sig-param">resource</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.requires_resource" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于当 <em>resource</em> 不可用时跳过测试的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.requires_docstrings">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">requires_docstrings</code><a class="headerlink" href="#test.support.requires_docstrings" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于仅当 <a class="reference internal" href="#test.support.HAVE_DOCSTRINGS" title="test.support.HAVE_DOCSTRINGS"><code class="xref py py-data docutils literal notranslate"><span class="pre">HAVE_DOCSTRINGS</span></code></a> 时才运行测试的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.cpython_only">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">cpython_only</code><span class="sig-paren">(</span><em class="sig-param">test</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.cpython_only" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>表示仅适用于 CPython 的测试的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.impl_detail">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">impl_detail</code><span class="sig-paren">(</span><em class="sig-param">msg=None</em>, <em class="sig-param">**guards</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.impl_detail" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于在 <em>guards</em> 上发起调用 <a class="reference internal" href="#test.support.check_impl_detail" title="test.support.check_impl_detail"><code class="xref py py-func docutils literal notranslate"><span class="pre">check_impl_detail()</span></code></a> 的装饰器。 如果调用返回 <code class="docutils literal notranslate"><span class="pre">False</span></code>,则使用 <em>msg</em> 作为跳过测试的原因。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.no_tracing">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">no_tracing</code><span class="sig-paren">(</span><em class="sig-param">func</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.no_tracing" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于在测试期间临时关闭追踪的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.refcount_test">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">refcount_test</code><span class="sig-paren">(</span><em class="sig-param">test</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.refcount_test" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于涉及引用计数的测试的装饰器。 如果测试不是由 CPython 运行则该装饰器不会运行测试。 在测试期间会取消设置任何追踪函数以由追踪函数导致的意外引用计数。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.reap_threads">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">reap_threads</code><span class="sig-paren">(</span><em class="sig-param">func</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.reap_threads" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于确保即使测试失败线程仍然会被清理的装饰器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.bigmemtest">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">bigmemtest</code><span class="sig-paren">(</span><em class="sig-param">size</em>, <em class="sig-param">memuse</em>, <em class="sig-param">dry_run=True</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.bigmemtest" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于大内存测试的装饰器。</p>
|
||
<p><em>size</em> 是测试所请求的大小(以任意的,由测试解读的单位。) <em>memuse</em> 是测试的每单元字节数,或是对它的良好估计。 例如,一个需要两个字节缓冲区,每个缓冲区 4 GiB,则可以用 <code class="docutils literal notranslate"><span class="pre">@bigmemtest(size=_4G,</span> <span class="pre">memuse=2)</span></code> 来装饰。</p>
|
||
<p><em>size</em> 参数通常作为额外参数传递给被测试的方法。 如果 <em>dry_run</em> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code>,则传给测试方法的值可能少于所请求的值。 如果 <em>dry_run</em> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code>,则意味着当当未指定 <code class="docutils literal notranslate"><span class="pre">-M</span></code> 时测试将不支持虚拟运行。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.bigaddrspacetest">
|
||
<code class="sig-prename descclassname">@</code><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">bigaddrspacetest</code><span class="sig-paren">(</span><em class="sig-param">f</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.bigaddrspacetest" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Decorator for tests that fill the address space. <em>f</em> is the function to
|
||
wrap.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.make_bad_fd">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">make_bad_fd</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.make_bad_fd" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>通过打开并关闭临时文件来创建一个无效的文件描述符,并返回其描述器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.check_syntax_error">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">check_syntax_error</code><span class="sig-paren">(</span><em class="sig-param">testcase</em>, <em class="sig-param">statement</em>, <em class="sig-param">errtext=''</em>, <em class="sig-param">*</em>, <em class="sig-param">lineno=None</em>, <em class="sig-param">offset=None</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.check_syntax_error" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于通过尝试编译 <em>statement</em> 来测试 <em>statement</em> 中的语法错误。 <em>testcase</em> 是测试的 <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> 实例。 <em>errtext</em> 是应当匹配所引发的 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> 的字符串表示形式的正则表达式。 如果 <em>lineno</em> 不为 <code class="docutils literal notranslate"><span class="pre">None</span></code>,则与异常所在的行进行比较。 如果 <em>offset</em> 不为 <code class="docutils literal notranslate"><span class="pre">None</span></code>,则与异常的偏移量进行比较。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.check_syntax_warning">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">check_syntax_warning</code><span class="sig-paren">(</span><em class="sig-param">testcase</em>, <em class="sig-param">statement</em>, <em class="sig-param">errtext=''</em>, <em class="sig-param">*</em>, <em class="sig-param">lineno=1</em>, <em class="sig-param">offset=None</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.check_syntax_warning" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于通过尝试编译 <em>statement</em> 来测试 <em>statement</em> 中的语法警告。 还会测试 <a class="reference internal" href="exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a> 是否只发出了一次,以及它在转成错误时是否将被转换为 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>。 <em>testcase</em> 是用于测试的 <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> 实例。 <em>errtext</em> 是应当匹配所发出的 <a class="reference internal" href="exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a> 以及所引发的 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> 的字符串表示形式的正则表达式。 如果 <em>lineno</em> 不为 <code class="docutils literal notranslate"><span class="pre">None</span></code>,则与警告和异常所在的行进行比较。 如果 <em>offset</em> 不为 <code class="docutils literal notranslate"><span class="pre">None</span></code>,则与异常的偏移量进行比较。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.8 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.open_urlresource">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">open_urlresource</code><span class="sig-paren">(</span><em class="sig-param">url</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.open_urlresource" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>打开 <em>url</em>。 如果打开失败,则引发 <a class="reference internal" href="#test.support.TestFailed" title="test.support.TestFailed"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TestFailed</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.import_module">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">import_module</code><span class="sig-paren">(</span><em class="sig-param">name</em>, <em class="sig-param">deprecated=False</em>, <em class="sig-param">*</em>, <em class="sig-param">required_on()</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.import_module" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>此函数会导入并返回指定名称的模块。 不同于正常的导入,如果模块无法被导入则此函数将引发 <a class="reference internal" href="unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-exc docutils literal notranslate"><span class="pre">unittest.SkipTest</span></code></a>。</p>
|
||
<p>如果 <em>deprecated</em> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 则在此导入操作期间模块和包的弃用消息会被屏蔽。 如果某个模块在特定平台上是必需的而在其他平台上是可选的,请为包含平台前缀的可迭代对象设置 <em>required_on</em>,此对象将与 <a class="reference internal" href="sys.html#sys.platform" title="sys.platform"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platform</span></code></a> 进行比对。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.1 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.import_fresh_module">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">import_fresh_module</code><span class="sig-paren">(</span><em class="sig-param">name</em>, <em class="sig-param">fresh=()</em>, <em class="sig-param">blocked=()</em>, <em class="sig-param">deprecated=False</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.import_fresh_module" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>此函数会在执行导入之前通过从 <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> 移除指定模块来导入并返回指定 Python 模块的新副本。 请注意这不同于 <code class="xref py py-func docutils literal notranslate"><span class="pre">reload()</span></code>,原来的模块不会受到此操作的影响。</p>
|
||
<p><em>fresh</em> 是包含在执行导入之前还要从 <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> 缓存中移除的附加模块名称的可迭代对象。</p>
|
||
<p><em>blocked</em> 是包含模块名称的可迭代对象,导入期间在模块缓存中它会被替换为 <code class="docutils literal notranslate"><span class="pre">None</span></code> 以确保尝试导入将引发 <a class="reference internal" href="exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>。</p>
|
||
<p>指定名称的模块以及任何在 <em>fresh</em> 和 <em>blocked</em> 形参中指明的模块会在开始导入之前被保存并在全新导入完成时被重新插入到 <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> 中。</p>
|
||
<p>如果 <em>deprecated</em> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 则在此导入操作期间模块和包的弃用消息会被屏蔽。</p>
|
||
<p>如果指定名称的模块无法被导入则此函数将引发 <a class="reference internal" href="exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>。</p>
|
||
<p>用法示例:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Get copies of the warnings module for testing without affecting the</span>
|
||
<span class="c1"># version being used by the rest of the test suite. One copy uses the</span>
|
||
<span class="c1"># C implementation, the other is forced to use the pure Python fallback</span>
|
||
<span class="c1"># implementation</span>
|
||
<span class="n">py_warnings</span> <span class="o">=</span> <span class="n">import_fresh_module</span><span class="p">(</span><span class="s1">'warnings'</span><span class="p">,</span> <span class="n">blocked</span><span class="o">=</span><span class="p">[</span><span class="s1">'_warnings'</span><span class="p">])</span>
|
||
<span class="n">c_warnings</span> <span class="o">=</span> <span class="n">import_fresh_module</span><span class="p">(</span><span class="s1">'warnings'</span><span class="p">,</span> <span class="n">fresh</span><span class="o">=</span><span class="p">[</span><span class="s1">'_warnings'</span><span class="p">])</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.1 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.modules_setup">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">modules_setup</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.modules_setup" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回 <a class="reference internal" href="sys.html#sys.modules" title="sys.modules"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.modules</span></code></a> 的副本。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.modules_cleanup">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">modules_cleanup</code><span class="sig-paren">(</span><em class="sig-param">oldmodules</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.modules_cleanup" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>移除 <em>oldmodules</em> 和 <code class="docutils literal notranslate"><span class="pre">encodings</span></code> 以外的模块以保留内部缓冲区。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.threading_setup">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">threading_setup</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.threading_setup" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回当前线程计数和悬空线程的副本。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.threading_cleanup">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">threading_cleanup</code><span class="sig-paren">(</span><em class="sig-param">*original_values</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.threading_cleanup" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>清理未在 <em>original_values</em> 中指定的线程。 被设计为如果有一个测试在后台离开正在运行的线程时会发出警告。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.join_thread">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">join_thread</code><span class="sig-paren">(</span><em class="sig-param">thread</em>, <em class="sig-param">timeout=30.0</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.join_thread" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>在 <em>timeout</em> 秒之内合并一个 <em>thread</em>。 如果线程在 <em>timeout</em> 秒后仍然存活则引发 <a class="reference internal" href="exceptions.html#AssertionError" title="AssertionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AssertionError</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.reap_children">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">reap_children</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.reap_children" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>只要有子进程启动就在 <code class="docutils literal notranslate"><span class="pre">test_main</span></code> 的末尾使用此函数。 这将有助于确保没有多余的子进程(僵尸)存在占用资源并在查找引用泄漏时造成问题。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.get_attribute">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">get_attribute</code><span class="sig-paren">(</span><em class="sig-param">obj</em>, <em class="sig-param">name</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.get_attribute" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>获取一个属性,如果引发了 <a class="reference internal" href="exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a> 则会引发 <a class="reference internal" href="unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-exc docutils literal notranslate"><span class="pre">unittest.SkipTest</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.bind_port">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">bind_port</code><span class="sig-paren">(</span><em class="sig-param">sock</em>, <em class="sig-param">host=HOST</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.bind_port" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将套接字绑定到一个空闲端口并返回端口号。 这依赖于瞬时端口以确保我们能使用一个未绑定端口。 这很重要因为可能会有许多测试同时运行,特别是在 buildbot 环境中。 如果 <code class="docutils literal notranslate"><span class="pre">sock.family</span></code> 为 <a class="reference internal" href="socket.html#socket.AF_INET" title="socket.AF_INET"><code class="xref py py-const docutils literal notranslate"><span class="pre">AF_INET</span></code></a> 而 <code class="docutils literal notranslate"><span class="pre">sock.type</span></code> 为 <a class="reference internal" href="socket.html#socket.SOCK_STREAM" title="socket.SOCK_STREAM"><code class="xref py py-const docutils literal notranslate"><span class="pre">SOCK_STREAM</span></code></a>,并且套接字上设置了 <code class="xref py py-const docutils literal notranslate"><span class="pre">SO_REUSEADDR</span></code> 或 <code class="xref py py-const docutils literal notranslate"><span class="pre">SO_REUSEPORT</span></code> 则此方法将引发异常。 测试绝不应该为 TCP/IP 套接字设置这些套接字选项。 唯一需要设置这些选项的情况是通过多个 UDP 套接字来测试组播。</p>
|
||
<p>此外,如果 <code class="xref py py-const docutils literal notranslate"><span class="pre">SO_EXCLUSIVEADDRUSE</span></code> 套接字选项是可用的(例如在 Windows 上),它将在套接字上被设置。 这将阻止其他任何人在测试期间绑定到我们的主机/端口。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.bind_unix_socket">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">bind_unix_socket</code><span class="sig-paren">(</span><em class="sig-param">sock</em>, <em class="sig-param">addr</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.bind_unix_socket" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>绑定一个 unix 套接字,如果 <a class="reference internal" href="exceptions.html#PermissionError" title="PermissionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PermissionError</span></code></a> 被引发则会引发 <a class="reference internal" href="unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-exc docutils literal notranslate"><span class="pre">unittest.SkipTest</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.catch_threading_exception">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">catch_threading_exception</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.catch_threading_exception" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>使用 <a class="reference internal" href="threading.html#threading.excepthook" title="threading.excepthook"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.excepthook()</span></code></a> 来捕获 <a class="reference internal" href="threading.html#threading.Thread" title="threading.Thread"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Thread</span></code></a> 异常的上下文管理器。</p>
|
||
<p>Attributes set when an exception is catched:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">exc_type</span></code></p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">exc_value</span></code></p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">exc_traceback</span></code></p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">thread</span></code></p></li>
|
||
</ul>
|
||
<p>参见 <a class="reference internal" href="threading.html#threading.excepthook" title="threading.excepthook"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.excepthook()</span></code></a> 文档。</p>
|
||
<p>这些属性在上下文管理器退出时将被删除。</p>
|
||
<p>用法:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">support</span><span class="o">.</span><span class="n">catch_threading_exception</span><span class="p">()</span> <span class="k">as</span> <span class="n">cm</span><span class="p">:</span>
|
||
<span class="c1"># code spawning a thread which raises an exception</span>
|
||
<span class="o">...</span>
|
||
|
||
<span class="c1"># check the thread exception, use cm attributes:</span>
|
||
<span class="c1"># exc_type, exc_value, exc_traceback, thread</span>
|
||
<span class="o">...</span>
|
||
|
||
<span class="c1"># exc_type, exc_value, exc_traceback, thread attributes of cm no longer</span>
|
||
<span class="c1"># exists at this point</span>
|
||
<span class="c1"># (to avoid reference cycles)</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.8 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.catch_unraisable_exception">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">catch_unraisable_exception</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.catch_unraisable_exception" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>使用 <a class="reference internal" href="sys.html#sys.unraisablehook" title="sys.unraisablehook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.unraisablehook()</span></code></a> 来捕获不可引发的异常的上下文管理器。</p>
|
||
<p>存储异常值 (<code class="docutils literal notranslate"><span class="pre">cm.unraisable.exc_value</span></code>) 会创建一个引用循环。 引用循环将在上下文管理器退出时被显式地打破。</p>
|
||
<p>存储对象 (<code class="docutils literal notranslate"><span class="pre">cm.unraisable.object</span></code>) 如果被设置为一个正在最终化的对象则可以恢复它。 退出上下文管理器将清除已存在对象。</p>
|
||
<p>用法:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">support</span><span class="o">.</span><span class="n">catch_unraisable_exception</span><span class="p">()</span> <span class="k">as</span> <span class="n">cm</span><span class="p">:</span>
|
||
<span class="c1"># code creating an "unraisable exception"</span>
|
||
<span class="o">...</span>
|
||
|
||
<span class="c1"># check the unraisable exception: use cm.unraisable</span>
|
||
<span class="o">...</span>
|
||
|
||
<span class="c1"># cm.unraisable attribute no longer exists at this point</span>
|
||
<span class="c1"># (to break a reference cycle)</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.8 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.find_unused_port">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">find_unused_port</code><span class="sig-paren">(</span><em class="sig-param">family=socket.AF_INET</em>, <em class="sig-param">socktype=socket.SOCK_STREAM</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.find_unused_port" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回一个应当适合绑定的未使用端口。 这是通过创建一个与 <code class="docutils literal notranslate"><span class="pre">sock</span></code> 形参相同协议族和类型的临时套接字来达成的 (默认为 <a class="reference internal" href="socket.html#socket.AF_INET" title="socket.AF_INET"><code class="xref py py-const docutils literal notranslate"><span class="pre">AF_INET</span></code></a>, <a class="reference internal" href="socket.html#socket.SOCK_STREAM" title="socket.SOCK_STREAM"><code class="xref py py-const docutils literal notranslate"><span class="pre">SOCK_STREAM</span></code></a>),并将其绑定到指定的主机地址 (默认为 <code class="docutils literal notranslate"><span class="pre">0.0.0.0</span></code>) 并将端口设为 0,以从 OS 引出一个未使用的瞬时端口。 这个临时套接字随后将被关闭并删除,然后返回该瞬时端口。</p>
|
||
<p>这个方法或 <a class="reference internal" href="#test.support.bind_port" title="test.support.bind_port"><code class="xref py py-func docutils literal notranslate"><span class="pre">bind_port()</span></code></a> 应当被用于任何在测试期间需要绑定到特定端口的测试。 具体使用哪个取决于调用方代码是否会创建 Python 套接字,或者是否需要在构造器中提供或向外部程序提供未使用的端口(例如传给 openssl 的 s_server 模式的 <code class="docutils literal notranslate"><span class="pre">-accept</span></code> 参数)。 在可能的情况下将总是优先使用 <a class="reference internal" href="#test.support.bind_port" title="test.support.bind_port"><code class="xref py py-func docutils literal notranslate"><span class="pre">bind_port()</span></code></a> 而非 <a class="reference internal" href="#test.support.find_unused_port" title="test.support.find_unused_port"><code class="xref py py-func docutils literal notranslate"><span class="pre">find_unused_port()</span></code></a>。 不建议使用硬编码的端口因为将使测试的多个实例无法同时运行,这对 buildbot 来说是个问题。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.load_package_tests">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">load_package_tests</code><span class="sig-paren">(</span><em class="sig-param">pkg_dir</em>, <em class="sig-param">loader</em>, <em class="sig-param">standard_tests</em>, <em class="sig-param">pattern</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.load_package_tests" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>在测试包中使用的 <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> <code class="docutils literal notranslate"><span class="pre">load_tests</span></code> 协议的通用实现。 <em>pkg_dir</em> 是包的根目录;<em>loader</em>, <em>standard_tests</em> 和 <em>pattern</em> 是 <code class="docutils literal notranslate"><span class="pre">load_tests</span></code> 所期望的参数。 在简单的情况下,测试包的 <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code> 可以是下面这样的:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
|
||
<span class="kn">from</span> <span class="nn">test.support</span> <span class="kn">import</span> <span class="n">load_package_tests</span>
|
||
|
||
<span class="k">def</span> <span class="nf">load_tests</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">):</span>
|
||
<span class="k">return</span> <span class="n">load_package_tests</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="vm">__file__</span><span class="p">),</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.fs_is_case_insensitive">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">fs_is_case_insensitive</code><span class="sig-paren">(</span><em class="sig-param">directory</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.fs_is_case_insensitive" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果 <em>directory</em> 的文件系统对大小写敏感则返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.detect_api_mismatch">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">detect_api_mismatch</code><span class="sig-paren">(</span><em class="sig-param">ref_api</em>, <em class="sig-param">other_api</em>, <em class="sig-param">*</em>, <em class="sig-param">ignore=()</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.detect_api_mismatch" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回未在 <em>other_api</em> 中找到的 <em>ref_api</em> 的属性、函数或方法的集合,除去在 <em>ignore</em> 中指明的要在这个检查中忽略的已定义条目列表。</p>
|
||
<p>在默认情况下这将跳过以 '_' 打头的私有属性但包括所有魔术方法,即以 '__' 打头和结尾的方法。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.5 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.patch">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">patch</code><span class="sig-paren">(</span><em class="sig-param">test_instance</em>, <em class="sig-param">object_to_patch</em>, <em class="sig-param">attr_name</em>, <em class="sig-param">new_value</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.patch" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用 <em>new_value</em> 重载 <em>object_to_patch.attr_name</em>。并向 <em>test_instance</em> 添加清理过程以便为 <em>attr_name</em> 恢复 <em>object_to_patch</em>。 <em>attr_name</em> 应当是 <em>object_to_patch</em> 的一个有效属性。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.run_in_subinterp">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">run_in_subinterp</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.run_in_subinterp" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>在子解释器中运行 <em>code</em>。 如果启用了 <a class="reference internal" href="tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> 则会引发 <a class="reference internal" href="unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-exc docutils literal notranslate"><span class="pre">unittest.SkipTest</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.check_free_after_iterating">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">check_free_after_iterating</code><span class="sig-paren">(</span><em class="sig-param">test</em>, <em class="sig-param">iter</em>, <em class="sig-param">cls</em>, <em class="sig-param">args=()</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.check_free_after_iterating" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Assert that <em>iter</em> is deallocated after iterating.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.missing_compiler_executable">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">missing_compiler_executable</code><span class="sig-paren">(</span><em class="sig-param">cmd_names=[]</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.missing_compiler_executable" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>检查在 <em>cmd_names</em> 中列出名称的或者当 <em>cmd_names</em> 为空时所有的编译器可执行文件是否存在并返回第一个丢失的可执行文件或者如果未发现任何丢失则返回 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.check__all__">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">check__all__</code><span class="sig-paren">(</span><em class="sig-param">test_case</em>, <em class="sig-param">module</em>, <em class="sig-param">name_of_module=None</em>, <em class="sig-param">extra=()</em>, <em class="sig-param">blacklist=()</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.check__all__" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>断言 <em>module</em> 的 <code class="docutils literal notranslate"><span class="pre">__all__</span></code> 变量包含全部公共名称。</p>
|
||
<p>模块的公共名称(它的 API)是根据它们是否符合公共名称惯例并在 <em>module</em> 中被定义来自动检测的。</p>
|
||
<p><em>name_of_module</em> 参数可以(用字符串或元组的形式)指定一个 API 可以被定义为什么模块以便被检测为一个公共 API。 一种这样的情况会在 <em>module</em> 从其他模块,可能是一个 C 后端 (如 <code class="docutils literal notranslate"><span class="pre">csv</span></code> 和它的 <code class="docutils literal notranslate"><span class="pre">_csv</span></code>) 导入其公共 API 的某一组成部分时发生。</p>
|
||
<p><em>extra</em> 参数可以是一个在其他情况下不会被自动检测为 "public" 的名称集合,例如没有适当 <code class="docutils literal notranslate"><span class="pre">__module__</span></code> 属性的对象。 如果提供该参数,它将被添加到自动检测到的对象中。</p>
|
||
<p>The <em>blacklist</em> argument can be a set of names that must not be treated as part of
|
||
the public API even though their names indicate otherwise.</p>
|
||
<p>用法示例:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">bar</span>
|
||
<span class="kn">import</span> <span class="nn">foo</span>
|
||
<span class="kn">import</span> <span class="nn">unittest</span>
|
||
<span class="kn">from</span> <span class="nn">test</span> <span class="kn">import</span> <span class="n">support</span>
|
||
|
||
<span class="k">class</span> <span class="nc">MiscTestCase</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
|
||
<span class="k">def</span> <span class="nf">test__all__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="n">support</span><span class="o">.</span><span class="n">check__all__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">foo</span><span class="p">)</span>
|
||
|
||
<span class="k">class</span> <span class="nc">OtherTestCase</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
|
||
<span class="k">def</span> <span class="nf">test__all__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="n">extra</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'BAR_CONST'</span><span class="p">,</span> <span class="s1">'FOO_CONST'</span><span class="p">}</span>
|
||
<span class="n">blacklist</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'baz'</span><span class="p">}</span> <span class="c1"># Undocumented name.</span>
|
||
<span class="c1"># bar imports part of its API from _bar.</span>
|
||
<span class="n">support</span><span class="o">.</span><span class="n">check__all__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bar</span><span class="p">,</span> <span class="p">(</span><span class="s1">'bar'</span><span class="p">,</span> <span class="s1">'_bar'</span><span class="p">),</span>
|
||
<span class="n">extra</span><span class="o">=</span><span class="n">extra</span><span class="p">,</span> <span class="n">blacklist</span><span class="o">=</span><span class="n">blacklist</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.6 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.adjust_int_max_str_digits">
|
||
<code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">adjust_int_max_str_digits</code><span class="sig-paren">(</span><em class="sig-param">max_digits</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.adjust_int_max_str_digits" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>此函数返回一个将在上下文生效期间改变全局 <a class="reference internal" href="sys.html#sys.set_int_max_str_digits" title="sys.set_int_max_str_digits"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.set_int_max_str_digits()</span></code></a> 设置的上下文管理器以便允许执行当在整数和字符串之间进行转换时需要对位数有不同限制的测试代码。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.8.14 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<p><a class="reference internal" href="#module-test.support" title="test.support: Support for Python's regression test suite."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code></a> 模块定义了以下的类:</p>
|
||
<dl class="class">
|
||
<dt id="test.support.TransientResource">
|
||
<em class="property">class </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TransientResource</code><span class="sig-paren">(</span><em class="sig-param">exc</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.TransientResource" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Instances are a context manager that raises <a class="reference internal" href="#test.support.ResourceDenied" title="test.support.ResourceDenied"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceDenied</span></code></a> if the
|
||
specified exception type is raised. Any keyword arguments are treated as
|
||
attribute/value pairs to be compared against any exception raised within the
|
||
<a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement. Only if all pairs match properly against
|
||
attributes on the exception is <a class="reference internal" href="#test.support.ResourceDenied" title="test.support.ResourceDenied"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceDenied</span></code></a> raised.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="test.support.EnvironmentVarGuard">
|
||
<em class="property">class </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">EnvironmentVarGuard</code><a class="headerlink" href="#test.support.EnvironmentVarGuard" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于临时性地设置或取消设置环境变量的类。 其实例可被用作上下文管理器并具有完整的字典接口用来查询/修改下层的 <code class="docutils literal notranslate"><span class="pre">os.environ</span></code>。 在从上下文管理器退出之后所有通过此实例对环境变量进行的修改都将被回滚。</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.1 版更改: </span>增加了字典接口。</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="test.support.EnvironmentVarGuard.set">
|
||
<code class="sig-prename descclassname">EnvironmentVarGuard.</code><code class="sig-name descname">set</code><span class="sig-paren">(</span><em class="sig-param">envvar</em>, <em class="sig-param">value</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.EnvironmentVarGuard.set" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>临时性地将环境变量 <code class="docutils literal notranslate"><span class="pre">envvar</span></code> 的值设为 <code class="docutils literal notranslate"><span class="pre">value</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="test.support.EnvironmentVarGuard.unset">
|
||
<code class="sig-prename descclassname">EnvironmentVarGuard.</code><code class="sig-name descname">unset</code><span class="sig-paren">(</span><em class="sig-param">envvar</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.EnvironmentVarGuard.unset" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>临时性地取消设置环境变量 <code class="docutils literal notranslate"><span class="pre">envvar</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="test.support.SuppressCrashReport">
|
||
<em class="property">class </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">SuppressCrashReport</code><a class="headerlink" href="#test.support.SuppressCrashReport" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个用于在预期会使子进程崩溃的测试时尽量防止弹出崩溃对话框的上下文管理器。</p>
|
||
<p>在 Windows 上,它会使用 <a class="reference external" href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx">SetErrorMode</a> 来禁用 Windows 错误报告对话框。</p>
|
||
<p>在 UNIX 上,会使用 <a class="reference internal" href="resource.html#resource.setrlimit" title="resource.setrlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">resource.setrlimit()</span></code></a> 来将 <a class="reference internal" href="resource.html#resource.RLIMIT_CORE" title="resource.RLIMIT_CORE"><code class="xref py py-attr docutils literal notranslate"><span class="pre">resource.RLIMIT_CORE</span></code></a> 的软限制设为 0 以防止创建核心转储文件。</p>
|
||
<p>在这两个平台上,旧值都将被 <a class="reference internal" href="../reference/datamodel.html#object.__exit__" title="object.__exit__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__exit__()</span></code></a> 恢复。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="test.support.CleanImport">
|
||
<em class="property">class </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">CleanImport</code><span class="sig-paren">(</span><em class="sig-param">*module_names</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.CleanImport" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>A context manager to force import to return a new module reference. This
|
||
is useful for testing module-level behaviors, such as the emission of a
|
||
DeprecationWarning on import. Example usage:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">CleanImport</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">):</span>
|
||
<span class="n">importlib</span><span class="o">.</span><span class="n">import_module</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span> <span class="c1"># New reference.</span>
|
||
</pre></div>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="test.support.DirsOnSysPath">
|
||
<em class="property">class </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">DirsOnSysPath</code><span class="sig-paren">(</span><em class="sig-param">*paths</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.DirsOnSysPath" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>A context manager to temporarily add directories to sys.path.</p>
|
||
<p>这将创建 <a class="reference internal" href="sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> 的一个副本,添加作为位置参数传入的任何目录,然后在上下文结束时将 <a class="reference internal" href="sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> 还原到副本的设置。</p>
|
||
<p>请注意该上下文管理器代码块中 <em>所有</em> 对 <a class="reference internal" href="sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> 的修改,包括对象的替换,都将在代码块结束时被还原。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="test.support.SaveSignals">
|
||
<em class="property">class </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">SaveSignals</code><a class="headerlink" href="#test.support.SaveSignals" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于保存和恢复由 Python 句柄的所注册的信号处理器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="test.support.Matcher">
|
||
<em class="property">class </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">Matcher</code><a class="headerlink" href="#test.support.Matcher" title="永久链接至目标">¶</a></dt>
|
||
<dd><dl class="method">
|
||
<dt id="test.support.Matcher.matches">
|
||
<code class="sig-name descname">matches</code><span class="sig-paren">(</span><em class="sig-param">self</em>, <em class="sig-param">d</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.Matcher.matches" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>尝试对单个字典与所提供的参数进行匹配。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="test.support.Matcher.match_value">
|
||
<code class="sig-name descname">match_value</code><span class="sig-paren">(</span><em class="sig-param">self</em>, <em class="sig-param">k</em>, <em class="sig-param">dv</em>, <em class="sig-param">v</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.Matcher.match_value" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>尝试对单个已存储值 (<em>dv</em>) 与所提供的值 (<em>v</em>) 进行匹配。</p>
|
||
</dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="test.support.WarningsRecorder">
|
||
<em class="property">class </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">WarningsRecorder</code><a class="headerlink" href="#test.support.WarningsRecorder" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用于为单元测试记录警告的类。 请参阅以上 <a class="reference internal" href="#test.support.check_warnings" title="test.support.check_warnings"><code class="xref py py-func docutils literal notranslate"><span class="pre">check_warnings()</span></code></a> 的文档来了解详情。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="test.support.BasicTestRunner">
|
||
<em class="property">class </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">BasicTestRunner</code><a class="headerlink" href="#test.support.BasicTestRunner" title="永久链接至目标">¶</a></dt>
|
||
<dd><dl class="method">
|
||
<dt id="test.support.BasicTestRunner.run">
|
||
<code class="sig-name descname">run</code><span class="sig-paren">(</span><em class="sig-param">test</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.BasicTestRunner.run" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>运行 <em>test</em> 并返回结果。</p>
|
||
</dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="test.support.TestHandler">
|
||
<em class="property">class </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">TestHandler</code><span class="sig-paren">(</span><em class="sig-param">logging.handlers.BufferingHandler</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.TestHandler" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Class for logging support.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="test.support.FakePath">
|
||
<em class="property">class </em><code class="sig-prename descclassname">test.support.</code><code class="sig-name descname">FakePath</code><span class="sig-paren">(</span><em class="sig-param">path</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.FakePath" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>简单的 <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>。 它实现了 <code class="xref py py-meth docutils literal notranslate"><span class="pre">__fspath__()</span></code> 方法,该方法将返回 <em>path</em> 参数。 如果 <em>path</em> 为一个异常,它将在 <code class="xref py py-meth docutils literal notranslate"><span class="pre">__fspath__()</span></code> 中被引发。</p>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
<section id="module-test.support.script_helper">
|
||
<span id="test-support-script-helper-utilities-for-the-python-execution-tests"></span><h1><a class="reference internal" href="#module-test.support.script_helper" title="test.support.script_helper: Support for Python's script execution tests."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support.script_helper</span></code></a> --- 用于 Python 执行测试工具<a class="headerlink" href="#module-test.support.script_helper" title="永久链接至标题">¶</a></h1>
|
||
<p><a class="reference internal" href="#module-test.support.script_helper" title="test.support.script_helper: Support for Python's script execution tests."><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support.script_helper</span></code></a> 模块提供了对 Python 的脚本执行测试的支持。</p>
|
||
<dl class="function">
|
||
<dt id="test.support.script_helper.interpreter_requires_environment">
|
||
<code class="sig-prename descclassname">test.support.script_helper.</code><code class="sig-name descname">interpreter_requires_environment</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#test.support.script_helper.interpreter_requires_environment" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果 <code class="docutils literal notranslate"><span class="pre">sys.executable</span> <span class="pre">interpreter</span></code> 需要环境变量才能运行则返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>。</p>
|
||
<p>这被设计用来配合 <code class="docutils literal notranslate"><span class="pre">@unittest.skipIf()</span></code> 以便标注需要使用to annotate tests that need to use an <code class="docutils literal notranslate"><span class="pre">assert_python*()</span></code> 函数来启动隔离模式 (<code class="docutils literal notranslate"><span class="pre">-I</span></code>) 或无环境模式 (<code class="docutils literal notranslate"><span class="pre">-E</span></code>) 子解释器的测试。</p>
|
||
<p>正常的编译和测试运行不会进入这种状况但它在尝试从一个使用 Python 的当前家目录查找逻辑找不到明确的家目录的解释器运行标准库测试套件时有可能发生。</p>
|
||
<p>设置 <span class="target" id="index-12"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHOME</span></code></a> 是一种能让大多数测试套件在这种情况下运行的办法。 <span class="target" id="index-13"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a> 或 <span class="target" id="index-14"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUSERSITE</span></code> 是另外两个可影响解释器是否能启动的常见环境变量。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.script_helper.run_python_until_end">
|
||
<code class="sig-prename descclassname">test.support.script_helper.</code><code class="sig-name descname">run_python_until_end</code><span class="sig-paren">(</span><em class="sig-param">*args</em>, <em class="sig-param">**env_vars</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.script_helper.run_python_until_end" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>基于 <em>env_vars</em> 设置环境以便在子进程中运行解释器。 它的值可以包括 <code class="docutils literal notranslate"><span class="pre">__isolated</span></code>, <code class="docutils literal notranslate"><span class="pre">__cleanenv</span></code>, <code class="docutils literal notranslate"><span class="pre">__cwd</span></code>, and <code class="docutils literal notranslate"><span class="pre">TERM</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.script_helper.assert_python_ok">
|
||
<code class="sig-prename descclassname">test.support.script_helper.</code><code class="sig-name descname">assert_python_ok</code><span class="sig-paren">(</span><em class="sig-param">*args</em>, <em class="sig-param">**env_vars</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.script_helper.assert_python_ok" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>断言附带 <em>args</em> 和可选的环境变量 <em>env_vars</em> 运行解释器会成功 (<code class="docutils literal notranslate"><span class="pre">rc</span> <span class="pre">==</span> <span class="pre">0</span></code>) 并返回一个 <code class="docutils literal notranslate"><span class="pre">(return</span> <span class="pre">code,</span> <span class="pre">stdout,</span> <span class="pre">stderr)</span></code> 元组。</p>
|
||
<p>If the <code class="docutils literal notranslate"><span class="pre">__cleanenv</span></code> keyword is set, <em>env_vars</em> is used as a fresh
|
||
environment.</p>
|
||
<p>Python is started in isolated mode (command line option <code class="docutils literal notranslate"><span class="pre">-I</span></code>),
|
||
except if the <code class="docutils literal notranslate"><span class="pre">__isolated</span></code> keyword is set to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.script_helper.assert_python_failure">
|
||
<code class="sig-prename descclassname">test.support.script_helper.</code><code class="sig-name descname">assert_python_failure</code><span class="sig-paren">(</span><em class="sig-param">*args</em>, <em class="sig-param">**env_vars</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.script_helper.assert_python_failure" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>断言附带 <em>args</em> 和可选的环境变量 <em>env_vars</em> 运行解释器会失败 (<code class="docutils literal notranslate"><span class="pre">rc</span> <span class="pre">!=</span> <span class="pre">0</span></code>) 并返回一个 <code class="docutils literal notranslate"><span class="pre">(return</span> <span class="pre">code,</span> <span class="pre">stdout,</span> <span class="pre">stderr)</span></code> 元组。</p>
|
||
<p>更多选项请参阅 <a class="reference internal" href="#test.support.script_helper.assert_python_ok" title="test.support.script_helper.assert_python_ok"><code class="xref py py-func docutils literal notranslate"><span class="pre">assert_python_ok()</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.script_helper.spawn_python">
|
||
<code class="sig-prename descclassname">test.support.script_helper.</code><code class="sig-name descname">spawn_python</code><span class="sig-paren">(</span><em class="sig-param">*args</em>, <em class="sig-param">stdout=subprocess.PIPE</em>, <em class="sig-param">stderr=subprocess.STDOUT</em>, <em class="sig-param">**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.script_helper.spawn_python" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>使用给定的参数运行一个 Python 子进程。</p>
|
||
<p><em>kw</em> 是要传给 <a class="reference internal" href="subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">subprocess.Popen()</span></code></a> 的额外关键字参数。 返回一个 <a class="reference internal" href="subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> 对象。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.script_helper.kill_python">
|
||
<code class="sig-prename descclassname">test.support.script_helper.</code><code class="sig-name descname">kill_python</code><span class="sig-paren">(</span><em class="sig-param">p</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.script_helper.kill_python" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>运行给定的 <a class="reference internal" href="subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> 进程直至完成并返回 stdout。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.script_helper.make_script">
|
||
<code class="sig-prename descclassname">test.support.script_helper.</code><code class="sig-name descname">make_script</code><span class="sig-paren">(</span><em class="sig-param">script_dir</em>, <em class="sig-param">script_basename</em>, <em class="sig-param">source</em>, <em class="sig-param">omit_suffix=False</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.script_helper.make_script" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>在路径 <em>script_dir</em> 和 <em>script_basename</em> 中创建包含 <em>source</em> 的脚本。 如果 <em>omit_suffix</em> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code>,则为名称添加 <code class="docutils literal notranslate"><span class="pre">.py</span></code>。 返回完整的脚本路径。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.script_helper.make_zip_script">
|
||
<code class="sig-prename descclassname">test.support.script_helper.</code><code class="sig-name descname">make_zip_script</code><span class="sig-paren">(</span><em class="sig-param">zip_dir</em>, <em class="sig-param">zip_basename</em>, <em class="sig-param">script_name</em>, <em class="sig-param">name_in_zip=None</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.script_helper.make_zip_script" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>使用 <em>zip_dir</em> 和 <em>zip_basename</em> 创建扩展名为 <code class="docutils literal notranslate"><span class="pre">zip</span></code> 的 zip 文件,其中包含 <em>script_name</em> 中的文件。 <em>name_in_zip</em> 为归档名。 返回一个包含 <code class="docutils literal notranslate"><span class="pre">(full</span> <span class="pre">path,</span> <span class="pre">full</span> <span class="pre">path</span> <span class="pre">of</span> <span class="pre">archive</span> <span class="pre">name)</span></code> 的元组。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.script_helper.make_pkg">
|
||
<code class="sig-prename descclassname">test.support.script_helper.</code><code class="sig-name descname">make_pkg</code><span class="sig-paren">(</span><em class="sig-param">pkg_dir</em>, <em class="sig-param">init_source=''</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.script_helper.make_pkg" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>创建一个名为 <em>pkg_dir</em> 的目录,其中包含一个 <code class="docutils literal notranslate"><span class="pre">__init__</span></code> 文件并以 <em>init_source</em> 作为其内容。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="test.support.script_helper.make_zip_pkg">
|
||
<code class="sig-prename descclassname">test.support.script_helper.</code><code class="sig-name descname">make_zip_pkg</code><span class="sig-paren">(</span><em class="sig-param">zip_dir</em>, <em class="sig-param">zip_basename</em>, <em class="sig-param">pkg_name</em>, <em class="sig-param">script_basename</em>, <em class="sig-param">source</em>, <em class="sig-param">depth=1</em>, <em class="sig-param">compiled=False</em><span class="sig-paren">)</span><a class="headerlink" href="#test.support.script_helper.make_zip_pkg" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>使用 <em>zip_dir</em> 和 <em>zip_basename</em> 创建一个 zip 包目录,其中包含一个空的 <code class="docutils literal notranslate"><span class="pre">__init__</span></code> 文件和一个包含 <em>source</em> 的文件 <em>script_basename</em>。 如果 <em>compiled</em> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code>,则两个源文件将被编译并添加到 zip 包中。 返回一个以完整 zip 路径和 zip 文件归档名为元素的元组。</p>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<h3><a href="../contents.html">目录</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code> --- Python 回归测试包</a><ul>
|
||
<li><a class="reference internal" href="#writing-unit-tests-for-the-test-package">为 <code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code> 包编写单元测试</a></li>
|
||
<li><a class="reference internal" href="#running-tests-using-the-command-line-interface">使用命令行界面运行测试</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#module-test.support"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support</span></code> --- 针对 Python 测试套件的工具</a></li>
|
||
<li><a class="reference internal" href="#module-test.support.script_helper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test.support.script_helper</span></code> --- 用于 Python 执行测试工具</a></li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="2to3.html"
|
||
title="上一章">2to3 - 自动将 Python 2 代码转为 Python 3 代码</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="debug.html"
|
||
title="下一章">调试和分析</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>本页</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">报告 Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/3.8/Doc/library/test.rst"
|
||
rel="nofollow">显示源代码
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>导航</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="总目录"
|
||
>索引</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python 模块索引"
|
||
>模块</a> |</li>
|
||
<li class="right" >
|
||
<a href="debug.html" title="调试和分析"
|
||
>下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="2to3.html" title="2to3 - 自动将 Python 2 代码转为 Python 3 代码"
|
||
>上一页</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.8.20 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="development.html" >开发工具</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
||
<input type="submit" value="转向" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
<div class="footer">
|
||
© <a href="../copyright.html">版权所有</a> 2001-2024, Python Software Foundation.
|
||
<br />
|
||
This page is licensed under the Python Software Foundation License Version 2.
|
||
<br />
|
||
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
|
||
<br />
|
||
|
||
<br />
|
||
|
||
The Python Software Foundation is a non-profit corporation.
|
||
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
||
<br />
|
||
<br />
|
||
|
||
最后更新于 12月 09, 2024.
|
||
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
|
||
<br />
|
||
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
|
||
</div>
|
||
|
||
</body>
|
||
</html> |