<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"lib.html" title='Python Library Reference'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"module-decimal.html" />
<link rel=
"prev" href=
"module-test.html" />
<link rel=
"parent" href=
"misc.html" />
<link rel=
"next" href=
"module-decimal.html" />
<meta name='aesop' content='information'
/>
<title>5.5 test.test_support -- Utility functions for tests
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"5.4.2 Running tests using"
href=
"regrtest.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"5. Miscellaneous Services"
href=
"misc.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"5.6 decimal "
href=
"module-decimal.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"regrtest.html">5.4.2 Running tests using
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"misc.html">5. Miscellaneous Services
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"module-decimal.html">5.6 decimal
</A>
<!--End of Navigation Panel-->
<H1><A NAME=
"SECTION007500000000000000000">
5.5 <tt class=
"module">test.test_support
</tt> --
Utility functions for tests
</A>
<A NAME=
"module-test.testsupport"></A>
The
<tt class=
"module">test.test_support
</tt> module provides support for Python's
This module defines the following exceptions:
<dl><dt><b><span class=
"typelabel">exception
</span> <tt id='l2h-
1181' xml:id='l2h-
1181'
class=
"exception">TestFailed
</tt></b></dt>
Exception to be raised when a test fails.
<dl><dt><b><span class=
"typelabel">exception
</span> <tt id='l2h-
1182' xml:id='l2h-
1182'
class=
"exception">TestSkipped
</tt></b></dt>
Subclass of
<tt class=
"exception">TestFailed
</tt>.
Raised when a test is skipped.
This occurs when a needed resource (such as a network connection) is not
available at the time of testing.
<dl><dt><b><span class=
"typelabel">exception
</span> <tt id='l2h-
1183' xml:id='l2h-
1183'
class=
"exception">ResourceDenied
</tt></b></dt>
Subclass of
<tt class=
"exception">TestSkipped
</tt>.
Raised when a resource (such as a network connection) is not available.
Raised by the
<tt class=
"function">requires()
</tt> function.
The
<tt class=
"module">test.test_support
</tt> module defines the following constants:
<dl><dt><b><tt id='l2h-
1184' xml:id='l2h-
1184'
>verbose
</tt></b></dt>
<tt class=
"constant">True
</tt> when verbose output is enabled.
Should be checked when more detailed information is desired about a running
<var>verbose
</var> is set by
<tt class=
"module">test.regrtest
</tt>.
<dl><dt><b><tt id='l2h-
1185' xml:id='l2h-
1185'
>have_unicode
</tt></b></dt>
<tt class=
"constant">True
</tt> when Unicode support is available.
<dl><dt><b><tt id='l2h-
1186' xml:id='l2h-
1186'
>is_jython
</tt></b></dt>
<tt class=
"constant">True
</tt> if the running interpreter is Jython.
<dl><dt><b><tt id='l2h-
1187' xml:id='l2h-
1187'
>TESTFN
</tt></b></dt>
Set to the path that a temporary file may be created at.
Any temporary that is created should be closed and unlinked (removed).
The
<tt class=
"module">test.test_support
</tt> module defines the following functions:
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
1188' xml:id='l2h-
1188'
class=
"function">forget
</tt></b>(
</nobr></td>
<td><var>module_name
</var>)
</td></tr></table></dt>
Removes the module named
<var>module_name
</var> from
<code>sys.modules
</code> and deletes
any byte-compiled files of the module.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
1189' xml:id='l2h-
1189'
class=
"function">is_resource_enabled
</tt></b>(
</nobr></td>
<td><var>resource
</var>)
</td></tr></table></dt>
Returns
<tt class=
"constant">True
</tt> if
<var>resource
</var> is enabled and available.
The list of available resources is only set when
<tt class=
"module">test.regrtest
</tt>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
1190' xml:id='l2h-
1190'
class=
"function">requires
</tt></b>(
</nobr></td>
<td><var>resource
</var><big>[
</big><var>, msg
</var><big>]
</big><var></var>)
</td></tr></table></dt>
Raises
<tt class=
"exception">ResourceDenied
</tt> if
<var>resource
</var> is not available.
<var>msg
</var> is the argument to
<tt class=
"exception">ResourceDenied
</tt> if it is raised.
Always returns true if called by a function whose
<code>__name__
</code> is
Used when tests are executed by
<tt class=
"module">test.regrtest
</tt>.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
1191' xml:id='l2h-
1191'
class=
"function">findfile
</tt></b>(
</nobr></td>
<td><var>filename
</var>)
</td></tr></table></dt>
Return the path to the file named
<var>filename
</var>.
If no match is found
<var>filename
</var> is returned.
This does not equal a failure since it could be the path to the file.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
1192' xml:id='l2h-
1192'
class=
"function">run_unittest
</tt></b>(
</nobr></td>
<td><var>*classes
</var>)
</td></tr></table></dt>
Execute
<tt class=
"class">unittest.TestCase
</tt> subclasses passed to the function.
The function scans the classes for methods starting with the prefix
"<tt class="samp
">test_</tt>" and executes the tests individually.
This is the preferred way to execute tests.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
1193' xml:id='l2h-
1193'
class=
"function">run_suite
</tt></b>(
</nobr></td>
<td><var>suite
</var><big>[
</big><var>, testclass
</var><big>]
</big><var></var>)
</td></tr></table></dt>
Execute the
<tt class=
"class">unittest.TestSuite
</tt> instance
<var>suite
</var>.
The optional argument
<var>testclass
</var> accepts one of the test classes in the
suite so as to print out more detailed information on where the testing suite
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"5.4.2 Running tests using"
href=
"regrtest.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"5. Miscellaneous Services"
href=
"misc.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"5.6 decimal "
href=
"module-decimal.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"regrtest.html">5.4.2 Running tests using
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"misc.html">5. Miscellaneous Services
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"module-decimal.html">5.6 decimal
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.