Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 272358a29dcac700c15f72584b3d4e55 > files > 927

python3-docs-3.7.10-1.1.mga7.noarch.rpm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>test — Regression tests package for Python &#8212; Python 3.7.10 documentation</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 3.7.10 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="next" title="Debugging and Profiling" href="debug.html" />
    <link rel="prev" title="2to3 - Automated Python 2 to 3 code translation" href="2to3.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/test.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="debug.html" title="Debugging and Profiling"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="2to3.html" title="2to3 - Automated Python 2 to 3 code translation"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.10 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="development.html" accesskey="U">Development Tools</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="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> — Regression tests package for Python<a class="headerlink" href="#module-test" title="Permalink to this headline">¶</a></h1>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The <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> package is meant for internal use by Python only. It is
documented for the benefit of the core developers of Python. Any use of
this package outside of Python’s standard library is discouraged as code
mentioned here can change or be removed without notice between releases of
Python.</p>
</div>
<hr class="docutils" />
<p>The <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> package contains all regression tests for Python as well as the
modules <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> and <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> is used to enhance your tests while
<code class="xref py py-mod docutils literal notranslate"><span class="pre">test.regrtest</span></code> drives the testing suite.</p>
<p>Each module in the <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> package whose name starts with <code class="docutils literal notranslate"><span class="pre">test_</span></code> is a
testing suite for a specific module or feature. All new tests should be written
using the <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> or <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> module.  Some older tests are
written using a “traditional” testing style that compares output printed to
<code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>; this style of test is considered deprecated.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt>Module <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>Writing PyUnit regression tests.</p>
</dd>
<dt>Module <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>Tests embedded in documentation strings.</p>
</dd>
</dl>
</div>
<div class="section" id="writing-unit-tests-for-the-test-package">
<span id="writing-tests"></span><h2>Writing Unit Tests for the <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> package<a class="headerlink" href="#writing-unit-tests-for-the-test-package" title="Permalink to this headline">¶</a></h2>
<p>It is preferred that tests that use the <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> module follow a few
guidelines. One is to name the test module by starting it with <code class="docutils literal notranslate"><span class="pre">test_</span></code> and end
it with the name of the module being tested. The test methods in the test module
should start with <code class="docutils literal notranslate"><span class="pre">test_</span></code> and end with a description of what the method is
testing. This is needed so that the methods are recognized by the test driver as
test methods. Also, no documentation string for the method should be included. A
comment (such as <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>) should be used
to provide documentation for test methods. This is done because documentation
strings get printed out if they exist and thus what test is being run is not
stated.</p>
<p>A basic boilerplate is often used:</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">&#39;__main__&#39;</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>This code pattern allows the testing suite to be run by <code class="xref py py-mod docutils literal notranslate"><span class="pre">test.regrtest</span></code>,
on its own as a script that supports the <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, or via the
<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">unittest</span></code> CLI.</p>
<p>The goal for regression testing is to try to break code. This leads to a few
guidelines to be followed:</p>
<ul>
<li><p>The testing suite should exercise all classes, functions, and constants. This
includes not just the external API that is to be presented to the outside
world but also “private” code.</p></li>
<li><p>Whitebox testing (examining the code being tested when the tests are being
written) is preferred. Blackbox testing (testing only the published user
interface) is not complete enough to make sure all boundary and edge cases
are tested.</p></li>
<li><p>Make sure all possible values are tested including invalid ones. This makes
sure that not only all valid values are acceptable but also that improper
values are handled correctly.</p></li>
<li><p>Exhaust as many code paths as possible. Test where branching occurs and thus
tailor input to make sure as many different paths through the code are taken.</p></li>
<li><p>Add an explicit test for any bugs discovered for the tested code. This will
make sure that the error does not crop up again if the code is changed in the
future.</p></li>
<li><p>Make sure to clean up after your tests (such as close and remove all temporary
files).</p></li>
<li><p>If a test is dependent on a specific condition of the operating system then
verify the condition already exists before attempting the test.</p></li>
<li><p>Import as few modules as possible and do it as soon as possible. This
minimizes external dependencies of tests and also minimizes possible anomalous
behavior from side-effects of importing a module.</p></li>
<li><p>Try to maximize code reuse. On occasion, tests will vary by something as small
as what type of input is used. Minimize code duplication by subclassing a
basic test class with a class that specifies the input:</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">&#39;abc&#39;</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>When using this pattern, remember that all classes that inherit from
<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> are run as tests.  The <code class="xref py py-class docutils literal notranslate"><span class="pre">Mixin</span></code> class in the example above
does not have any data and so can’t be run by itself, thus it does not
inherit from <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">See also</p>
<dl class="simple">
<dt>Test Driven Development</dt><dd><p>A book by Kent Beck on writing tests before code.</p>
</dd>
</dl>
</div>
</div>
<div class="section" id="running-tests-using-the-command-line-interface">
<span id="regrtest"></span><h2>Running tests using the command-line interface<a class="headerlink" href="#running-tests-using-the-command-line-interface" title="Permalink to this headline">¶</a></h2>
<p>The <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> package can be run as a script to drive Python’s regression
test suite, thanks to the <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> option: <strong class="program">python -m test</strong>. Under
the hood, it uses <code class="xref py py-mod docutils literal notranslate"><span class="pre">test.regrtest</span></code>; the call <strong class="program">python -m
test.regrtest</strong> used in previous Python versions still works.  Running the
script by itself automatically starts running all regression tests in the
<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> package. It does this by finding all modules in the package whose
name starts with <code class="docutils literal notranslate"><span class="pre">test_</span></code>, importing them, and executing the function
<code class="xref py py-func docutils literal notranslate"><span class="pre">test_main()</span></code> if present or loading the tests via
unittest.TestLoader.loadTestsFromModule if <code class="docutils literal notranslate"><span class="pre">test_main</span></code> does not exist.  The
names of tests to execute may also be passed to the script. Specifying a single
regression test (<strong class="program">python -m test test_spam</strong>) will minimize output and
only print whether the test passed or failed.</p>
<p>Running <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> directly allows what resources are available for
tests to use to be set. You do this by using the <code class="docutils literal notranslate"><span class="pre">-u</span></code> command-line
option. Specifying <code class="docutils literal notranslate"><span class="pre">all</span></code> as the value for the <code class="docutils literal notranslate"><span class="pre">-u</span></code> option enables all
possible resources: <strong class="program">python -m test -uall</strong>.
If all but one resource is desired (a more common case), a
comma-separated list of resources that are not desired may be listed after
<code class="docutils literal notranslate"><span class="pre">all</span></code>. The command <strong class="program">python -m test -uall,-audio,-largefile</strong>
will run <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> with all resources except the <code class="docutils literal notranslate"><span class="pre">audio</span></code> and
<code class="docutils literal notranslate"><span class="pre">largefile</span></code> resources. For a list of all resources and more command-line
options, run <strong class="program">python -m test -h</strong>.</p>
<p>Some other ways to execute the regression tests depend on what platform the
tests are being executed on. On Unix, you can run <strong class="program">make test</strong> at the
top-level directory where Python was built. On Windows,
executing <strong class="program">rt.bat</strong> from your <code class="file docutils literal notranslate"><span class="pre">PCbuild</span></code> directory will run all
regression tests.</p>
</div>
</div>
<div class="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> — Utilities for the Python test suite<a class="headerlink" href="#module-test.support" title="Permalink to this headline">¶</a></h1>
<p>The <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> module provides support for Python’s regression
test suite.</p>
<div class="admonition note">
<p class="admonition-title">Note</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> is not a public module.  It is documented here to help
Python developers write tests.  The API of this module is subject to change
without backwards compatibility concerns between releases.</p>
</div>
<p>This module defines the following exceptions:</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="Permalink to this definition">¶</a></dt>
<dd><p>Exception to be raised when a test fails. This is deprecated in favor of
<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>-based tests and <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>’s assertion
methods.</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="Permalink to this definition">¶</a></dt>
<dd><p>Subclass of <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>. Raised when a resource (such as a
network connection) is not available. Raised by the <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>
function.</p>
</dd></dl>

<p>The <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> module defines the following constants:</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="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> when verbose output is enabled. Should be checked when more
detailed information is desired about a running test. <em>verbose</em> is set by
<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="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the running interpreter is Jython.</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="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the system is Android.</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="Permalink to this definition">¶</a></dt>
<dd><p>Path for shell if not on Windows; otherwise <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="Permalink to this definition">¶</a></dt>
<dd><p>A non-ASCII character encodable by <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>.</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="Permalink to this definition">¶</a></dt>
<dd><p>Set to a name that is safe to use as the name of a temporary file.  Any
temporary file that is created should be closed and unlinked (removed).</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="Permalink to this definition">¶</a></dt>
<dd><p>Set to a non-ASCII name for a temporary file.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Set to a filename (str type) that should not be able to be encoded by file
system encoding in strict mode.  It may be <code class="docutils literal notranslate"><span class="pre">None</span></code> if it’s not possible to
generate such a filename.</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="Permalink to this definition">¶</a></dt>
<dd><p>Set to a filename (bytes type) that should not be able to be decoded by
file system encoding in strict mode.  It may be <code class="docutils literal notranslate"><span class="pre">None</span></code> if it’s not
possible to generate such a filename.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Set to <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="Permalink to this definition">¶</a></dt>
<dd><p>Set when tests can be skipped when they are not useful for 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="Permalink to this definition">¶</a></dt>
<dd><p>A constant that is likely larger than the underlying OS pipe buffer size,
to make writes blocking.</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="Permalink to this definition">¶</a></dt>
<dd><p>A constant that is likely larger than the underlying OS socket buffer size,
to make writes blocking.</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="Permalink to this definition">¶</a></dt>
<dd><p>Set to the top level directory that contains <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="Permalink to this definition">¶</a></dt>
<dd><p>Set to the top level directory for the test package.</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="Permalink to this definition">¶</a></dt>
<dd><p>Set to the <code class="docutils literal notranslate"><span class="pre">data</span></code> directory within the test package.</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="Permalink to this definition">¶</a></dt>
<dd><p>Set to <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> for big memory tests.</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="Permalink to this definition">¶</a></dt>
<dd><p>Set by <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> as the memory limit for big memory tests.
Limited by <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="Permalink to this definition">¶</a></dt>
<dd><p>Set by <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> as the memory limit for big memory tests.  Not
limited by <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="Permalink to this definition">¶</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Define the URL of a dedicated HTTP server for the network tests.</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="Permalink to this definition">¶</a></dt>
<dd><p>Object that is equal to anything.  Used to test mixed type comparison.</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="Permalink to this definition">¶</a></dt>
<dd><p>Object that is greater than anything (except itself).
Used to test mixed type comparison.</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="Permalink to this definition">¶</a></dt>
<dd><p>Object that is less than anything (except itself).
Used to test mixed type comparison.</p>
</dd></dl>

<p>The <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> module defines the following functions:</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="Permalink to this definition">¶</a></dt>
<dd><p>Remove the module named <em>module_name</em> from <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> and delete any
byte-compiled files of the module.</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="Permalink to this definition">¶</a></dt>
<dd><p>Delete <em>name</em> from <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code>.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Move a PEP 3147/488 pyc file to its legacy pyc location and return the file
system path to the legacy pyc file.  The <em>source</em> value is the file system
path to the source file.  It does not need to exist, however the PEP
3147/488 pyc file must exist.</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="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if <em>resource</em> is enabled and available. The list of
available resources is only set when <code class="xref py py-mod docutils literal notranslate"><span class="pre">test.regrtest</span></code> is executing the
tests.</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="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if Python was not built with <code class="docutils literal notranslate"><span class="pre">-O0</span></code> or <code class="docutils literal notranslate"><span class="pre">-Og</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="Permalink to this definition">¶</a></dt>
<dd><p>Return <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="Permalink to this definition">¶</a></dt>
<dd><p>Raise <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 <em>resource</em> is not available. <em>msg</em> is the
argument to <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 it is raised. Always returns
<code class="docutils literal notranslate"><span class="pre">True</span></code> if called by a function whose <code class="docutils literal notranslate"><span class="pre">__name__</span></code> is <code class="docutils literal notranslate"><span class="pre">'__main__'</span></code>.
Used when tests are executed by <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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Return a repr of <em>dict</em> with keys sorted.</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="Permalink to this definition">¶</a></dt>
<dd><p>Return the path to the file named <em>filename</em>. If no match is found
<em>filename</em> is returned. This does not equal a failure since it could be the
path to the file.</p>
<p>Setting <em>subdir</em> indicates a relative path to use to find the file
rather than looking directly in the path directories.</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="Permalink to this definition">¶</a></dt>
<dd><p>Create an empty file with <em>filename</em>.  If it already exists, truncate it.</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="Permalink to this definition">¶</a></dt>
<dd><p>Count the number of open file descriptors.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Execute <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> subclasses passed to the function. The
function scans the classes for methods starting with the prefix <code class="docutils literal notranslate"><span class="pre">test_</span></code>
and executes the tests individually.</p>
<p>It is also legal to pass strings as parameters; these should be keys in
<code class="docutils literal notranslate"><span class="pre">sys.modules</span></code>. Each associated module will be scanned by
<code class="docutils literal notranslate"><span class="pre">unittest.TestLoader.loadTestsFromModule()</span></code>. This is usually seen in the
following <code class="xref py py-func docutils literal notranslate"><span class="pre">test_main()</span></code> function:</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>This will run all tests defined in the named module.</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="Permalink to this definition">¶</a></dt>
<dd><p>Run <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> on the given <em>module</em>.  Return
<code class="docutils literal notranslate"><span class="pre">(failure_count,</span> <span class="pre">test_count)</span></code>.</p>
<p>If <em>verbosity</em> is <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> is run with verbosity
set to <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>.  Otherwise, it is run with verbosity set to
<code class="docutils literal notranslate"><span class="pre">None</span></code>.  <em>optionflags</em> is passed as <code class="docutils literal notranslate"><span class="pre">optionflags</span></code> to
<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="Permalink to this definition">¶</a></dt>
<dd><p>Set the <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> to the given <em>interval</em>.  Defines
a minimum interval for Android systems to prevent the system from hanging.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>A convenience wrapper for <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> that makes it
easier to test that a warning was correctly raised.  It is approximately
equivalent to calling <code class="docutils literal notranslate"><span class="pre">warnings.catch_warnings(record=True)</span></code> with
<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> set to <code class="docutils literal notranslate"><span class="pre">always</span></code> and with the option to
automatically validate the results that are recorded.</p>
<p><code class="docutils literal notranslate"><span class="pre">check_warnings</span></code> accepts 2-tuples of the form <code class="docutils literal notranslate"><span class="pre">(&quot;message</span> <span class="pre">regexp&quot;,</span>
<span class="pre">WarningCategory)</span></code> as positional arguments. If one or more <em>filters</em> are
provided, or if the optional keyword argument <em>quiet</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>,
it checks to make sure the warnings are as expected:  each specified filter
must match at least one of the warnings raised by the enclosed code or the
test fails, and if any warnings are raised that do not match any of the
specified filters the test fails.  To disable the first of these checks,
set <em>quiet</em> to <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
<p>If no arguments are specified, it defaults to:</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">&quot;&quot;</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>In this case all warnings are caught and no errors are raised.</p>
<p>On entry to the context manager, a <code class="xref py py-class docutils literal notranslate"><span class="pre">WarningRecorder</span></code> instance is
returned. The underlying warnings list from
<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> is available via the recorder object’s
<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> attribute.  As a convenience, the attributes of the object
representing the most recent warning can also be accessed directly through
the recorder object (see example below).  If no warning has been raised,
then any of the attributes that would otherwise be expected on an object
representing a warning will return <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
<p>The recorder object also has a <code class="xref py py-meth docutils literal notranslate"><span class="pre">reset()</span></code> method, which clears the
warnings list.</p>
<p>The context manager is designed to be used like this:</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">&quot;assertion is always true&quot;</span><span class="p">,</span> <span class="ne">SyntaxWarning</span><span class="p">),</span>
                    <span class="p">(</span><span class="s2">&quot;&quot;</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">&#39;assert(False, &quot;Hey!&quot;)&#39;</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">&quot;Hide me!&quot;</span><span class="p">))</span>
</pre></div>
</div>
<p>In this case if either warning was not raised, or some other warning was
raised, <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> would raise an error.</p>
<p>When a test needs to look more deeply into the warnings, rather than
just checking whether or not they occurred, code like this can be used:</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">&quot;foo&quot;</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">&quot;foo&quot;</span>
    <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;bar&quot;</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">&quot;bar&quot;</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">&quot;foo&quot;</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">&quot;bar&quot;</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>Here all warnings will be caught, and the test code tests the captured
warnings directly.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 3.2: </span>New optional arguments <em>filters</em> and <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="Permalink to this definition">¶</a></dt>
<dd><p>Context manager to check that no <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> was raised.  You
must remove the object which may emit <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> before the
end of the context manager.</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="Permalink to this definition">¶</a></dt>
<dd><p>Set the values for <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> and <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> for big
memory tests.</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="Permalink to this definition">¶</a></dt>
<dd><p>Store the value from <em>stdout</em>.  It is meant to hold the stdout at the
time the regrtest began.</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="Permalink to this definition">¶</a></dt>
<dd><p>Return the original stdout set by <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> or
<code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code> if it’s not set.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of command line arguments reproducing the current settings
in <code class="docutils literal notranslate"><span class="pre">sys.flags</span></code> and <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="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of command line arguments reproducing the current
optimization settings in <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="Permalink to this definition">¶</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>A context managers that temporarily replaces the named stream with
<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> object.</p>
<p>Example use with output streams:</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">&quot;hello&quot;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;error&quot;</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">&quot;hello</span><span class="se">\n</span><span class="s2">&quot;</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">&quot;error</span><span class="se">\n</span><span class="s2">&quot;</span>
</pre></div>
</div>
<p>Example use with input stream:</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">&#39;hello</span><span class="se">\n</span><span class="s1">&#39;</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">&quot;hello&quot;</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="Permalink to this definition">¶</a></dt>
<dd><p>A context manager that creates a temporary directory at <em>path</em> and
yields the directory.</p>
<p>If <em>path</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, the temporary directory is created using
<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>.  If <em>quiet</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, the context manager
raises an exception on error.  Otherwise, if <em>path</em> is specified and
cannot be created, only a warning is issued.</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="Permalink to this definition">¶</a></dt>
<dd><p>A context manager that temporarily changes the current working
directory to <em>path</em> and yields the directory.</p>
<p>If <em>quiet</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, the context manager raises an exception
on error.  Otherwise, it issues only a warning and keeps the current
working directory the same.</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="Permalink to this definition">¶</a></dt>
<dd><p>A context manager that temporarily creates a new directory and
changes the current working directory (CWD).</p>
<p>The context manager creates a temporary directory in the current
directory with name <em>name</em> before temporarily changing the current
working directory.  If <em>name</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, the temporary directory is
created using <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>If <em>quiet</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code> and it is not possible to create or change
the CWD, an error is raised.  Otherwise, only a warning is raised
and the original CWD is used.</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="Permalink to this definition">¶</a></dt>
<dd><p>A context manager that temporarily sets the process umask.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Force as many objects as possible to be collected.  This is needed because
timely deallocation is not guaranteed by the garbage collector.  This means
that <code class="docutils literal notranslate"><span class="pre">__del__</span></code> methods may be called later than expected and weakrefs
may remain alive for longer than expected.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Context manager to swap out an attribute with a new object.</p>
<p>Usage:</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">&quot;attr&quot;</span><span class="p">,</span> <span class="mi">5</span><span class="p">):</span>
    <span class="o">...</span>
</pre></div>
</div>
<p>This will set <code class="docutils literal notranslate"><span class="pre">obj.attr</span></code> to 5 for the duration of the <code class="docutils literal notranslate"><span class="pre">with</span></code> block,
restoring the old value at the end of the block.  If <code class="docutils literal notranslate"><span class="pre">attr</span></code> doesn’t
exist on <code class="docutils literal notranslate"><span class="pre">obj</span></code>, it will be created and then deleted at the end of the
block.</p>
<p>The old value (or <code class="docutils literal notranslate"><span class="pre">None</span></code> if it doesn’t exist) will be assigned to the
target of the “as” clause, if there is one.</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="Permalink to this definition">¶</a></dt>
<dd><p>Context manager to swap out an item with a new object.</p>
<p>Usage:</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">&quot;item&quot;</span><span class="p">,</span> <span class="mi">5</span><span class="p">):</span>
    <span class="o">...</span>
</pre></div>
</div>
<p>This will set <code class="docutils literal notranslate"><span class="pre">obj[&quot;item&quot;]</span></code> to 5 for the duration of the <code class="docutils literal notranslate"><span class="pre">with</span></code> block,
restoring the old value at the end of the block. If <code class="docutils literal notranslate"><span class="pre">item</span></code> doesn’t
exist on <code class="docutils literal notranslate"><span class="pre">obj</span></code>, it will be created and then deleted at the end of the
block.</p>
<p>The old value (or <code class="docutils literal notranslate"><span class="pre">None</span></code> if it doesn’t exist) will be assigned to the
target of the “as” clause, if there is one.</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="Permalink to this definition">¶</a></dt>
<dd><p>Context manager to wait until all threads created in the <code class="docutils literal notranslate"><span class="pre">with</span></code> statement
exit.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>For testcase <em>test</em>, assert that the <code class="docutils literal notranslate"><span class="pre">sys.getsizeof</span></code> for <em>o</em> plus the GC
header size equals <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="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the OS supports symbolic links, <code class="docutils literal notranslate"><span class="pre">False</span></code>
otherwise.</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="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the OS supports xattr, <code class="docutils literal notranslate"><span class="pre">False</span></code>
otherwise.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.skip_unless_symlink">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>A decorator for running tests that require support for symbolic links.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.skip_unless_xattr">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>A decorator for running tests that require support for xattr.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.skip_unless_bind_unix_socket">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</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">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>A decorator to conditionally mark tests with
<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>. Any use of this decorator should
have an associated comment identifying the relevant tracker issue.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.run_with_locale">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>A decorator for running a function in a different locale, correctly
resetting it after it has finished.  <em>catstr</em> is the locale category as
a string (for example <code class="docutils literal notranslate"><span class="pre">&quot;LC_ALL&quot;</span></code>).  The <em>locales</em> passed will be tried
sequentially, and the first valid locale will be used.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.run_with_tz">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>A decorator for running a function in a specific timezone, correctly
resetting it after it has finished.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.requires_freebsd_version">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</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">&#64;</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="Permalink to this definition">¶</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">&#64;</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="Permalink to this definition">¶</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">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator for skipping tests on non-IEEE 754 platforms.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.requires_zlib">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator for skipping tests if <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> doesn’t exist.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.requires_gzip">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator for skipping tests if <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> doesn’t exist.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.requires_bz2">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator for skipping tests if <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> doesn’t exist.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.requires_lzma">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator for skipping tests if <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> doesn’t exist.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.requires_resource">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator for skipping tests if <em>resource</em> is not available.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.requires_docstrings">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator for only running the test if <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">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator for tests only applicable to CPython.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.impl_detail">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator for invoking <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> on <em>guards</em>.  If that
returns <code class="docutils literal notranslate"><span class="pre">False</span></code>, then uses <em>msg</em> as the reason for skipping the test.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.no_tracing">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator to temporarily turn off tracing for the duration of the test.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.refcount_test">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator for tests which involve reference counting.  The decorator does
not run the test if it is not run by CPython.  Any trace function is unset
for the duration of the test to prevent unexpected refcounts caused by
the trace function.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.reap_threads">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator to ensure the threads are cleaned up even if the test fails.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.bigmemtest">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</a></dt>
<dd><p>Decorator for bigmem tests.</p>
<p><em>size</em> is a requested size for the test (in arbitrary, test-interpreted
units.)  <em>memuse</em> is the number of bytes per unit for the test, or a good
estimate of it.  For example, a test that needs two byte buffers, of 4 GiB
each, could be decorated with <code class="docutils literal notranslate"><span class="pre">&#64;bigmemtest(size=_4G,</span> <span class="pre">memuse=2)</span></code>.</p>
<p>The <em>size</em> argument is normally passed to the decorated test method as an
extra argument.  If <em>dry_run</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the value passed to the test
method may be less than the requested value.  If <em>dry_run</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, it
means the test doesn’t support dummy runs when <code class="docutils literal notranslate"><span class="pre">-M</span></code> is not specified.</p>
</dd></dl>

<dl class="function">
<dt id="test.support.bigaddrspacetest">
<code class="sig-prename descclassname">&#64;</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Create an invalid file descriptor by opening and closing a temporary file,
and returning its descriptor.</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="Permalink to this definition">¶</a></dt>
<dd><p>Test for syntax errors in <em>statement</em> by attempting to compile <em>statement</em>.
<em>testcase</em> is the <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> instance for the test.  <em>errtext</em> is the
text of the error raised by <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>.  If <em>lineno</em> is not None,
compares to the line of the <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>.  If <em>offset</em> is not None,
compares to the offset of the <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>.</p>
</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="Permalink to this definition">¶</a></dt>
<dd><p>Open <em>url</em>.  If open fails, raises <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="Permalink to this definition">¶</a></dt>
<dd><p>This function imports and returns the named module. Unlike a normal
import, this function raises <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> if the module
cannot be imported.</p>
<p>Module and package deprecation messages are suppressed during this import
if <em>deprecated</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>.  If a module is required on a platform but
optional for others, set <em>required_on</em> to an iterable of platform prefixes
which will be compared against <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">New in version 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="Permalink to this definition">¶</a></dt>
<dd><p>This function imports and returns a fresh copy of the named Python module
by removing the named module from <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> before doing the import.
Note that unlike <code class="xref py py-func docutils literal notranslate"><span class="pre">reload()</span></code>, the original module is not affected by
this operation.</p>
<p><em>fresh</em> is an iterable of additional module names that are also removed
from the <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> cache before doing the import.</p>
<p><em>blocked</em> is an iterable of module names that are replaced with <code class="docutils literal notranslate"><span class="pre">None</span></code>
in the module cache during the import to ensure that attempts to import
them raise <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>The named module and any modules named in the <em>fresh</em> and <em>blocked</em>
parameters are saved before starting the import and then reinserted into
<code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> when the fresh import is complete.</p>
<p>Module and package deprecation messages are suppressed during this import
if <em>deprecated</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
<p>This function will raise <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> if the named module cannot be
imported.</p>
<p>Example use:</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">&#39;warnings&#39;</span><span class="p">,</span> <span class="n">blocked</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;_warnings&#39;</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">&#39;warnings&#39;</span><span class="p">,</span> <span class="n">fresh</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;_warnings&#39;</span><span class="p">])</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified added">New in version 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="Permalink to this definition">¶</a></dt>
<dd><p>Return a copy of <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="Permalink to this definition">¶</a></dt>
<dd><p>Remove modules except for <em>oldmodules</em> and <code class="docutils literal notranslate"><span class="pre">encodings</span></code> in order to
preserve internal cache.</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="Permalink to this definition">¶</a></dt>
<dd><p>Return current thread count and copy of dangling threads.</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="Permalink to this definition">¶</a></dt>
<dd><p>Cleanup up threads not specified in <em>original_values</em>.  Designed to emit
a warning if a test leaves running threads in the background.</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="Permalink to this definition">¶</a></dt>
<dd><p>Join a <em>thread</em> within <em>timeout</em>.  Raise an <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> if thread
is still alive after <em>timeout</em> seconds.</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="Permalink to this definition">¶</a></dt>
<dd><p>Use this at the end of <code class="docutils literal notranslate"><span class="pre">test_main</span></code> whenever sub-processes are started.
This will help ensure that no extra children (zombies) stick around to
hog resources and create problems when looking for refleaks.</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="Permalink to this definition">¶</a></dt>
<dd><p>Get an attribute, raising <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> if <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>
is raised.</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="Permalink to this definition">¶</a></dt>
<dd><p>Bind the socket to a free port and return the port number.  Relies on
ephemeral ports in order to ensure we are using an unbound port.  This is
important as many tests may be running simultaneously, especially in a
buildbot environment.  This method raises an exception if the
<code class="docutils literal notranslate"><span class="pre">sock.family</span></code> is <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> and <code class="docutils literal notranslate"><span class="pre">sock.type</span></code> is
<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>, and the socket has
<code class="xref py py-const docutils literal notranslate"><span class="pre">SO_REUSEADDR</span></code> or <code class="xref py py-const docutils literal notranslate"><span class="pre">SO_REUSEPORT</span></code> set on it.
Tests should never set these socket options for TCP/IP sockets.
The only case for setting these options is testing multicasting via
multiple UDP sockets.</p>
<p>Additionally, if the <code class="xref py py-const docutils literal notranslate"><span class="pre">SO_EXCLUSIVEADDRUSE</span></code> socket option is
available (i.e. on Windows), it will be set on the socket.  This will
prevent anyone else from binding to our host/port for the duration of the
test.</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="Permalink to this definition">¶</a></dt>
<dd><p>Bind a unix socket, raising <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> if
<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> is raised.</p>
</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="Permalink to this definition">¶</a></dt>
<dd><p>Returns an unused port that should be suitable for binding.  This is
achieved by creating a temporary socket with the same family and type as
the <code class="docutils literal notranslate"><span class="pre">sock</span></code> parameter (default is <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>),
and binding it to the specified host address (defaults to <code class="docutils literal notranslate"><span class="pre">0.0.0.0</span></code>)
with the port set to 0, eliciting an unused ephemeral port from the OS.
The temporary socket is then closed and deleted, and the ephemeral port is
returned.</p>
<p>Either this method or <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> should be used for any tests
where a server socket needs to be bound to a particular port for the
duration of the test.
Which one to use depends on whether the calling code is creating a Python
socket, or if an unused port needs to be provided in a constructor
or passed to an external program (i.e. the <code class="docutils literal notranslate"><span class="pre">-accept</span></code> argument to
openssl’s s_server mode).  Always prefer <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> over
<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> where possible.  Using a hard coded port is
discouraged since it can make multiple instances of the test impossible to
run simultaneously, which is a problem for buildbots.</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="Permalink to this definition">¶</a></dt>
<dd><p>Generic implementation of the <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> protocol for
use in test packages.  <em>pkg_dir</em> is the root directory of the package;
<em>loader</em>, <em>standard_tests</em>, and <em>pattern</em> are the arguments expected by
<code class="docutils literal notranslate"><span class="pre">load_tests</span></code>.  In simple cases, the test package’s <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code>
can be the following:</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="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the file system for <em>directory</em> is case-insensitive.</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="Permalink to this definition">¶</a></dt>
<dd><p>Returns the set of attributes, functions or methods of <em>ref_api</em> not
found on <em>other_api</em>, except for a defined list of items to be
ignored in this check specified in <em>ignore</em>.</p>
<p>By default this skips private attributes beginning with ‘_’ but
includes all magic methods, i.e. those starting and ending in ‘__’.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 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="Permalink to this definition">¶</a></dt>
<dd><p>Override <em>object_to_patch.attr_name</em> with <em>new_value</em>.  Also add
cleanup procedure to <em>test_instance</em> to restore <em>object_to_patch</em> for
<em>attr_name</em>.  The <em>attr_name</em> should be a valid attribute for
<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="Permalink to this definition">¶</a></dt>
<dd><p>Run <em>code</em> in subinterpreter.  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> if
<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> is enabled.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Check for the existence of the compiler executables whose names are listed
in <em>cmd_names</em> or all the compiler executables when <em>cmd_names</em> is empty
and return the first missing executable or <code class="docutils literal notranslate"><span class="pre">None</span></code> when none is found
missing.</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="Permalink to this definition">¶</a></dt>
<dd><p>Assert that the <code class="docutils literal notranslate"><span class="pre">__all__</span></code> variable of <em>module</em> contains all public names.</p>
<p>The module’s public names (its API) are detected automatically
based on whether they match the public name convention and were defined in
<em>module</em>.</p>
<p>The <em>name_of_module</em> argument can specify (as a string or tuple thereof) what
module(s) an API could be defined in order to be detected as a public
API. One case for this is when <em>module</em> imports part of its public API from
other modules, possibly a C backend (like <code class="docutils literal notranslate"><span class="pre">csv</span></code> and its <code class="docutils literal notranslate"><span class="pre">_csv</span></code>).</p>
<p>The <em>extra</em> argument can be a set of names that wouldn’t otherwise be automatically
detected as “public”, like objects without a proper <code class="docutils literal notranslate"><span class="pre">__module__</span></code>
attribute. If provided, it will be added to the automatically detected ones.</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>Example use:</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">&#39;BAR_CONST&#39;</span><span class="p">,</span> <span class="s1">&#39;FOO_CONST&#39;</span><span class="p">}</span>
        <span class="n">blacklist</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;baz&#39;</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">&#39;bar&#39;</span><span class="p">,</span> <span class="s1">&#39;_bar&#39;</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">New in version 3.6.</span></p>
</div>
</dd></dl>

<p>The <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> module defines the following classes:</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Class used to temporarily set or unset environment variables.  Instances can
be used as a context manager and have a complete dictionary interface for
querying/modifying the underlying <code class="docutils literal notranslate"><span class="pre">os.environ</span></code>. After exit from the
context manager all changes to environment variables done through this
instance will be rolled back.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 3.1: </span>Added dictionary interface.</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="Permalink to this definition">¶</a></dt>
<dd><p>Temporarily set the environment variable <code class="docutils literal notranslate"><span class="pre">envvar</span></code> to the value of
<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="Permalink to this definition">¶</a></dt>
<dd><p>Temporarily unset the environment variable <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="Permalink to this definition">¶</a></dt>
<dd><p>A context manager used to try to prevent crash dialog popups on tests that
are expected to crash a subprocess.</p>
<p>On Windows, it disables Windows Error Reporting dialogs using
<a class="reference external" href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx">SetErrorMode</a>.</p>
<p>On 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> is used to set
<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>’s soft limit to 0 to prevent coredump file
creation.</p>
<p>On both platforms, the old value is restored by <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="Permalink to this definition">¶</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">&#39;foo&#39;</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">&#39;foo&#39;</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="Permalink to this definition">¶</a></dt>
<dd><p>A context manager to temporarily add directories to sys.path.</p>
<p>This makes a copy of <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>, appends any directories given
as positional arguments, then reverts <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> to the copied
settings when the context ends.</p>
<p>Note that <em>all</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> modifications in the body of the
context manager, including replacement of the object,
will be reverted at the end of the block.</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="Permalink to this definition">¶</a></dt>
<dd><p>Class to save and restore signal handlers registered by the Python signal
handler.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Try to match a single dict with the supplied arguments.</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="Permalink to this definition">¶</a></dt>
<dd><p>Try to match a single stored value (<em>dv</em>) with a supplied value (<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="Permalink to this definition">¶</a></dt>
<dd><p>Class used to record warnings for unit tests. See documentation of
<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> above for more details.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Run <em>test</em> and return the result.</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="Permalink to this definition">¶</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="Permalink to this definition">¶</a></dt>
<dd><p>Simple <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.  It implements the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__fspath__()</span></code>
method which just returns the <em>path</em> argument.  If <em>path</em> is an exception,
it will be raised in <code class="xref py py-meth docutils literal notranslate"><span class="pre">__fspath__()</span></code>.</p>
</dd></dl>

</div>
<div class="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> — Utilities for the Python execution tests<a class="headerlink" href="#module-test.support.script_helper" title="Permalink to this headline">¶</a></h1>
<p>The <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> module provides support for Python’s
script execution tests.</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="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if <code class="docutils literal notranslate"><span class="pre">sys.executable</span> <span class="pre">interpreter</span></code> requires environment
variables in order to be able to run at all.</p>
<p>This is designed to be used with <code class="docutils literal notranslate"><span class="pre">&#64;unittest.skipIf()</span></code> to annotate tests
that need to use an <code class="docutils literal notranslate"><span class="pre">assert_python*()</span></code> function to launch an isolated
mode (<code class="docutils literal notranslate"><span class="pre">-I</span></code>) or no environment mode (<code class="docutils literal notranslate"><span class="pre">-E</span></code>) sub-interpreter process.</p>
<p>A normal build &amp; test does not run into this situation but it can happen
when trying to run the standard library test suite from an interpreter that
doesn’t have an obvious home with Python’s current home finding logic.</p>
<p>Setting <span class="target" id="index-0"></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> is one way to get most of the testsuite to run
in that situation.  <span class="target" id="index-1"></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> or <span class="target" id="index-2"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUSERSITE</span></code> are
other common environment variables that might impact whether or not the
interpreter can start.</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="Permalink to this definition">¶</a></dt>
<dd><p>Set up the environment based on <em>env_vars</em> for running the interpreter
in a subprocess.  The values can include <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="Permalink to this definition">¶</a></dt>
<dd><p>Assert that running the interpreter with <em>args</em> and optional environment
variables <em>env_vars</em> succeeds (<code class="docutils literal notranslate"><span class="pre">rc</span> <span class="pre">==</span> <span class="pre">0</span></code>) and return a <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> tuple.</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="Permalink to this definition">¶</a></dt>
<dd><p>Assert that running the interpreter with <em>args</em> and optional environment
variables <em>env_vars</em> fails (<code class="docutils literal notranslate"><span class="pre">rc</span> <span class="pre">!=</span> <span class="pre">0</span></code>) and return a <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> tuple.</p>
<p>See <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> for more options.</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="Permalink to this definition">¶</a></dt>
<dd><p>Run a Python subprocess with the given arguments.</p>
<p><em>kw</em> is extra keyword args to pass to <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>. Returns 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> object.</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="Permalink to this definition">¶</a></dt>
<dd><p>Run the given <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> process until completion and return
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="Permalink to this definition">¶</a></dt>
<dd><p>Create script containing <em>source</em> in path <em>script_dir</em> and <em>script_basename</em>.
If <em>omit_suffix</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, append <code class="docutils literal notranslate"><span class="pre">.py</span></code> to the name.  Return the full
script path.</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="Permalink to this definition">¶</a></dt>
<dd><p>Create zip file at <em>zip_dir</em> and <em>zip_basename</em> with extension <code class="docutils literal notranslate"><span class="pre">zip</span></code> which
contains the files in <em>script_name</em>. <em>name_in_zip</em> is the archive name.
Return a tuple containing <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="Permalink to this definition">¶</a></dt>
<dd><p>Create a directory named <em>pkg_dir</em> containing an <code class="docutils literal notranslate"><span class="pre">__init__</span></code> file with
<em>init_source</em> as its contents.</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="Permalink to this definition">¶</a></dt>
<dd><p>Create a zip package directory with a path of <em>zip_dir</em> and <em>zip_basename</em>
containing an empty <code class="docutils literal notranslate"><span class="pre">__init__</span></code> file and a file <em>script_basename</em>
containing the <em>source</em>.  If <em>compiled</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, both source files will
be compiled and added to the zip package.  Return a tuple of the full zip
path and the archive name for the zip file.</p>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code> — Regression tests package for Python</a><ul>
<li><a class="reference internal" href="#writing-unit-tests-for-the-test-package">Writing Unit Tests for the <code class="xref py py-mod docutils literal notranslate"><span class="pre">test</span></code> package</a></li>
<li><a class="reference internal" href="#running-tests-using-the-command-line-interface">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> — Utilities for the Python test suite</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> — Utilities for the Python execution tests</a></li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="2to3.html"
                        title="previous chapter">2to3 - Automated Python 2 to 3 code translation</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="debug.html"
                        title="next chapter">Debugging and Profiling</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">Report a Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/test.rst"
            rel="nofollow">Show Source
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="debug.html" title="Debugging and Profiling"
             >next</a> |</li>
        <li class="right" >
          <a href="2to3.html" title="2to3 - Automated Python 2 to 3 code translation"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.10 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="development.html" >Development Tools</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 2001-2021, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Feb 26, 2021.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.3.1.
    </div>

  </body>
</html>