Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-decimal.html" /> | |
13 | <link rel="prev" href="module-test.html" /> | |
14 | <link rel="parent" href="misc.html" /> | |
15 | <link rel="next" href="module-decimal.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>5.5 test.test_support -- Utility functions for tests</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="5.4.2 Running tests using" | |
25 | href="regrtest.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services" | |
28 | href="misc.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="5.6 decimal " | |
31 | href="module-decimal.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="regrtest.html">5.4.2 Running tests using</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-decimal.html">5.6 decimal </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION007500000000000000000"> | |
56 | 5.5 <tt class="module">test.test_support</tt> -- | |
57 | Utility functions for tests</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-test.testsupport"></A> | |
62 | ||
63 | <P> | |
64 | The <tt class="module">test.test_support</tt> module provides support for Python's | |
65 | regression tests. | |
66 | ||
67 | <P> | |
68 | This module defines the following exceptions: | |
69 | ||
70 | <P> | |
71 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-1181' xml:id='l2h-1181' class="exception">TestFailed</tt></b></dt> | |
72 | <dd> | |
73 | Exception to be raised when a test fails. | |
74 | </dd></dl> | |
75 | ||
76 | <P> | |
77 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-1182' xml:id='l2h-1182' class="exception">TestSkipped</tt></b></dt> | |
78 | <dd> | |
79 | Subclass of <tt class="exception">TestFailed</tt>. | |
80 | Raised when a test is skipped. | |
81 | This occurs when a needed resource (such as a network connection) is not | |
82 | available at the time of testing. | |
83 | </dd></dl> | |
84 | ||
85 | <P> | |
86 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-1183' xml:id='l2h-1183' class="exception">ResourceDenied</tt></b></dt> | |
87 | <dd> | |
88 | Subclass of <tt class="exception">TestSkipped</tt>. | |
89 | Raised when a resource (such as a network connection) is not available. | |
90 | Raised by the <tt class="function">requires()</tt> function. | |
91 | </dd></dl> | |
92 | ||
93 | <P> | |
94 | The <tt class="module">test.test_support</tt> module defines the following constants: | |
95 | ||
96 | <P> | |
97 | <dl><dt><b><tt id='l2h-1184' xml:id='l2h-1184'>verbose</tt></b></dt> | |
98 | <dd> | |
99 | <tt class="constant">True</tt> when verbose output is enabled. | |
100 | Should be checked when more detailed information is desired about a running | |
101 | test. | |
102 | <var>verbose</var> is set by <tt class="module">test.regrtest</tt>. | |
103 | </dd></dl> | |
104 | ||
105 | <P> | |
106 | <dl><dt><b><tt id='l2h-1185' xml:id='l2h-1185'>have_unicode</tt></b></dt> | |
107 | <dd> | |
108 | <tt class="constant">True</tt> when Unicode support is available. | |
109 | </dd></dl> | |
110 | ||
111 | <P> | |
112 | <dl><dt><b><tt id='l2h-1186' xml:id='l2h-1186'>is_jython</tt></b></dt> | |
113 | <dd> | |
114 | <tt class="constant">True</tt> if the running interpreter is Jython. | |
115 | </dd></dl> | |
116 | ||
117 | <P> | |
118 | <dl><dt><b><tt id='l2h-1187' xml:id='l2h-1187'>TESTFN</tt></b></dt> | |
119 | <dd> | |
120 | Set to the path that a temporary file may be created at. | |
121 | Any temporary that is created should be closed and unlinked (removed). | |
122 | </dd></dl> | |
123 | ||
124 | <P> | |
125 | The <tt class="module">test.test_support</tt> module defines the following functions: | |
126 | ||
127 | <P> | |
128 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
129 | <td><nobr><b><tt id='l2h-1188' xml:id='l2h-1188' class="function">forget</tt></b>(</nobr></td> | |
130 | <td><var>module_name</var>)</td></tr></table></dt> | |
131 | <dd> | |
132 | Removes the module named <var>module_name</var> from <code>sys.modules</code> and deletes | |
133 | any byte-compiled files of the module. | |
134 | </dl> | |
135 | ||
136 | <P> | |
137 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
138 | <td><nobr><b><tt id='l2h-1189' xml:id='l2h-1189' class="function">is_resource_enabled</tt></b>(</nobr></td> | |
139 | <td><var>resource</var>)</td></tr></table></dt> | |
140 | <dd> | |
141 | Returns <tt class="constant">True</tt> if <var>resource</var> is enabled and available. | |
142 | The list of available resources is only set when <tt class="module">test.regrtest</tt> | |
143 | is executing the tests. | |
144 | </dl> | |
145 | ||
146 | <P> | |
147 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
148 | <td><nobr><b><tt id='l2h-1190' xml:id='l2h-1190' class="function">requires</tt></b>(</nobr></td> | |
149 | <td><var>resource</var><big>[</big><var>, msg</var><big>]</big><var></var>)</td></tr></table></dt> | |
150 | <dd> | |
151 | Raises <tt class="exception">ResourceDenied</tt> if <var>resource</var> is not available. | |
152 | <var>msg</var> is the argument to <tt class="exception">ResourceDenied</tt> if it is raised. | |
153 | Always returns true if called by a function whose <code>__name__</code> is | |
154 | <code>'__main__'</code>. | |
155 | Used when tests are executed by <tt class="module">test.regrtest</tt>. | |
156 | </dl> | |
157 | ||
158 | <P> | |
159 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
160 | <td><nobr><b><tt id='l2h-1191' xml:id='l2h-1191' class="function">findfile</tt></b>(</nobr></td> | |
161 | <td><var>filename</var>)</td></tr></table></dt> | |
162 | <dd> | |
163 | Return the path to the file named <var>filename</var>. | |
164 | If no match is found <var>filename</var> is returned. | |
165 | This does not equal a failure since it could be the path to the file. | |
166 | </dl> | |
167 | ||
168 | <P> | |
169 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
170 | <td><nobr><b><tt id='l2h-1192' xml:id='l2h-1192' class="function">run_unittest</tt></b>(</nobr></td> | |
171 | <td><var>*classes</var>)</td></tr></table></dt> | |
172 | <dd> | |
173 | Execute <tt class="class">unittest.TestCase</tt> subclasses passed to the function. | |
174 | The function scans the classes for methods starting with the prefix | |
175 | "<tt class="samp">test_</tt>" and executes the tests individually. | |
176 | This is the preferred way to execute tests. | |
177 | </dl> | |
178 | ||
179 | <P> | |
180 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
181 | <td><nobr><b><tt id='l2h-1193' xml:id='l2h-1193' class="function">run_suite</tt></b>(</nobr></td> | |
182 | <td><var>suite</var><big>[</big><var>, testclass</var><big>]</big><var></var>)</td></tr></table></dt> | |
183 | <dd> | |
184 | Execute the <tt class="class">unittest.TestSuite</tt> instance <var>suite</var>. | |
185 | The optional argument <var>testclass</var> accepts one of the test classes in the | |
186 | suite so as to print out more detailed information on where the testing suite | |
187 | originated from. | |
188 | </dl> | |
189 | ||
190 | <DIV CLASS="navigation"> | |
191 | <div class='online-navigation'> | |
192 | <p></p><hr /> | |
193 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
194 | <tr> | |
195 | <td class='online-navigation'><a rel="prev" title="5.4.2 Running tests using" | |
196 | href="regrtest.html"><img src='../icons/previous.png' | |
197 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
198 | <td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services" | |
199 | href="misc.html"><img src='../icons/up.png' | |
200 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
201 | <td class='online-navigation'><a rel="next" title="5.6 decimal " | |
202 | href="module-decimal.html"><img src='../icons/next.png' | |
203 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
204 | <td align="center" width="100%">Python Library Reference</td> | |
205 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
206 | href="contents.html"><img src='../icons/contents.png' | |
207 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
208 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
209 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
210 | <td class='online-navigation'><a rel="index" title="Index" | |
211 | href="genindex.html"><img src='../icons/index.png' | |
212 | border='0' height='32' alt='Index' width='32' /></A></td> | |
213 | </tr></table> | |
214 | <div class='online-navigation'> | |
215 | <b class="navlabel">Previous:</b> | |
216 | <a class="sectref" rel="prev" href="regrtest.html">5.4.2 Running tests using</A> | |
217 | <b class="navlabel">Up:</b> | |
218 | <a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A> | |
219 | <b class="navlabel">Next:</b> | |
220 | <a class="sectref" rel="next" href="module-decimal.html">5.6 decimal </A> | |
221 | </div> | |
222 | </div> | |
223 | <hr /> | |
224 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
225 | </DIV> | |
226 | <!--End of Navigation Panel--> | |
227 | <ADDRESS> | |
228 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
229 | </ADDRESS> | |
230 | </BODY> | |
231 | </HTML> |