@@ -2,137 +2,42 @@ \section{\module{test} ---
22 Regression tests package for Python }
33
44\declaremodule {standard}{test}
5-
65\sectionauthor {Brett Cannon}{brett@python.org}
6+ \modulesynopsis {Regression tests package containing the testing suite
7+ for Python.}
78
89
9- \modulesynopsis {Regression tests package containing the testing suite for
10- Python.}
11-
12-
13- The \module {test} package contains all regression tests for Python as well as
14- the modules \module {test_support} and \module {regrtest.py}.
15- \module {test_support} is used to enhance your tests while \module {regrtest.py}
16- drives the testing suite.
10+ The \module {test} package contains all regression tests for Python as
11+ well as the modules \module {test.test_support} and
12+ \module {test.regrtest}. \module {test.test_support} is used to enhance
13+ your tests while \module {test.regrtest} drives the testing suite.
1714
1815Each module in the \module {test} package whose name starts with
19- \code {' test_' } is a testing suite for a specific module or feature.
20- All new tests should be written using the \module {unittest} module; using
21- \module {unittest} is not required but makes the tests more flexible and
22- maintenance of the tests easier.
23- Some older tests are written to use \module {doctest} and a `` traditional''
24- testing style; these styles of tests will not be covered.
16+ \samp { test_} is a testing suite for a specific module or feature.
17+ All new tests should be written using the \refmodule {unittest} module;
18+ using \refmodule {unittest} is not required but makes the tests more
19+ flexible and maintenance of the tests easier. Some older tests are
20+ written to use \refmodule {doctest} and a `` traditional'' testing
21+ style; these styles of tests will not be covered.
2522
2623\begin {seealso }
2724\seemodule {unittest}{Writing PyUnit regression tests.}
2825\seemodule {doctest}{Tests embedded in documentation strings.}
2926\end {seealso }
3027
3128
32- \subsection {\module {test.test_support} --- Utility functions for tests }
33- \declaremodule [test.testsupport]{standard}{test.test_support}
34-
35- The \module {test.test_support} module contains functions for assisting
36- with writing regression tests.
37-
38- The \module {test.test_support} module defines the following exceptions:
39-
40- \begin {excdesc }{TestFailed}
41- Exception to be raised when a test fails.
42- \end {excdesc }
43-
44- \begin {excdesc }{TestSkipped}
45- Subclass of \exception {TestFailed}.
46- Raised when a test is skipped.
47- This occurs when a needed resource (such as a network connection) is not
48- available at the time of testing.
49- \end {excdesc }
50-
51- \begin {excdesc }{ResourceDenied}
52- Subclass of \exception {TestSkipped}.
53- Raised when a resource (such as a network connection) is not available.
54- Raised by the \function {requires} function.
55- \end {excdesc }
56-
57-
58- The \module {test_support} module defines the following constants:
59-
60- \begin {datadesc }{verbose}
61- \constant {True} when verbose output is enabled.
62- Should be checked when more detailed information is desired about a running
63- test.
64- \var {verbose} is set by \module {regrtest.py}.
65- \end {datadesc }
66-
67- \begin {datadesc }{have_unicode}
68- \constant {True} when Unicode support is available.
69- \end {datadesc }
70-
71- \begin {datadesc }{is_jython}
72- \constant {True} if the running interpreter is Jython.
73- \end {datadesc }
74-
75- \begin {datadesc }{TESTFN}
76- Set to the path that a temporary file may be created at.
77- Any temporary that is created should be closed and unlinked (removed).
78- \end {datadesc }
79-
80-
81- The \module {test_support} module defines the following functions:
82-
83- \begin {funcdesc }{forget}{module_name}
84- Removes the module named \var {module_name} from \module {sys.modules} and deletes
85- any byte-compiled files of the module.
86- \end {funcdesc }
87-
88- \begin {funcdesc }{is_resource_enabled}{resource}
89- Returns \constant {True} if \var {resource} is enabled and available.
90- The list of available resources is only set when \module {regrtest.py} is
91- executing the tests.
92- \end {funcdesc }
93-
94- \begin {funcdesc }{requires}{resource\optional {, msg}}
95- Raises \exception {ResourceDenied} if \var {resource} is not available.
96- \var {msg} is the argument to \exception {ResourceDenied} if it is raised.
97- Always returns true if called by a function whose \var {__name__} is
98- \code {"__main__"}.
99- Used when tests are executed by \module {regrtest.py}.
100- \end {funcdesc }
101-
102- \begin {funcdesc }{findfile}{filename}
103- Return the path to the file named \var {filename}.
104- If no match is found \var {filename} is returned.
105- This does not equal a failure since it could be the path to the file.
106- \end {funcdesc }
107-
108- \begin {funcdesc }{run_unittest}{*classes}
109- Execute \class {unittest.TestCase} subclasses passed to the function.
110- The function scans the classes for methods starting with the name
111- \code {"test_"} and executes the tests individually.
112- This is the preferred way to execute tests.
113- \end {funcdesc }
114-
115- \begin {funcdesc }{run_suite}{suite\optional {, testclass=None}}
116- Execute the \class {unittest.TestSuite} instance, \var {suite}.
117- The optional argument \var {testclass} accepts one of the test classes in the
118- suite so as to print out more detailed information on where the testing suite
119- originated from.
120- \end {funcdesc }
121-
122-
123-
12429\subsection {Writing Unit Tests for the \module {test} package%
12530 \label {writing-tests } }
12631
12732It is preferred that tests for the \module {test} package use the
12833\refmodule {unittest} module and follow a few guidelines.
129- One is to have the name of all the test methods start with \code {" test_" } as
34+ One is to have the name of all the test methods start with \samp { test_} as
13035well as the module's name.
13136This is needed so that the methods are recognized by the test driver as
13237test methods.
13338Also, no documentation string for the method should be included.
13439A comment (such as
135- \code {\# Tests function returns only True or False}) should be used to provide
40+ \samp {\# Tests function returns only True or False}) should be used to provide
13641documentation for test methods.
13742This is done because documentation strings get printed out if they exist and
13843thus what test is being run is not stated.
@@ -178,8 +83,8 @@ \subsection{Writing Unit Tests for the \module{test} package%
17883 test_main()
17984\end {verbatim }
18085
181- This boilerplate code allows the testing suite to be run by \module {regrtest.py}
182- as well as on its own as a script.
86+ This boilerplate code allows the testing suite to be run by
87+ \module {test.regrtest} as well as on its own as a script.
18388
18489The goal for regression testing is to try to break code.
18590This leads to a few guidelines to be followed:
@@ -208,8 +113,8 @@ \subsection{Writing Unit Tests for the \module{test} package%
208113 This minimizes external dependencies of tests and also minimizes possible
209114 anomalous behavior from side-effects of importing a module.
210115\item Try to maximize code reuse.
211- On occasion tests will vary by something as small as what type of input
212- they take .
116+ On occasion, tests will vary by something as small as what type
117+ of input is used .
213118 Minimize code duplication by subclassing a basic test class with a class
214119 that specifies the input:
215120\begin {verbatim }
@@ -232,45 +137,138 @@ \subsection{Writing Unit Tests for the \module{test} package%
232137\end {itemize }
233138
234139\begin {seealso }
235- \seetitle {Test Driven Development}{A book by Kent Beck on writing tests before
236- code}
140+ \seetitle {Test Driven Development}
141+ {A book by Kent Beck on writing tests before code. }
237142\end {seealso }
238143
239144
145+ \subsection {Running tests Using \module {test.regrtest} \label {regrtest } }
240146
241- \subsection {Running tests Using \module {regrtest.py} \label {regrtest } }
242-
243- \module {regrtest.py} is the script used to drive Python's regression test
244- suite.
147+ \module {test.regrtest} can be used as a script to drive Python's
148+ regression test suite.
245149Running the script by itself automatically starts running all
246150regression tests in the \module {test} package.
247151It does this by finding all modules in the package whose name starts with
248- \code {test_}, importing them, and executing the function \function {test_main}
249- if present.
152+ \samp {test_}, importing them, and executing the function
153+ \function {test_main()} if present.
250154The names of tests to execute may also be passed to the script.
251- Specifying a single regression test (\code {python regrtest.py test_spam.py})
252- will minimize output and only print whether the test passed or failed and thus
253- minimize output.
155+ Specifying a single regression test (\program {python regrtest.py}
156+ \programopt {test_spam.py}) will minimize output and only print whether
157+ the test passed or failed and thus minimize output.
254158
255- Running \module {regrtest.py } directly allows what resources are
159+ Running \module {test.regrtest } directly allows what resources are
256160available for tests to use to be set.
257- You do this by using the \code {-u} command-line option.
258- Run \code {python regrtest.py -uall} to turn on all resources;
259- specifying \code {all} as an option for \code {-u} enables all possible
260- resources.
161+ You do this by using the \programopt {-u} command-line option.
162+ Run \program {python regrtest.py} \programopt { -uall} to turn on all
163+ resources; specifying \programopt {all} as an option for
164+ \programopt {-u} enables all possible resources.
261165If all but one resource is desired (a more common case), a
262166comma-separated list of resources that are not desired may be listed after
263- \code {all}.
264- The command \code {python regrtest.py -uall,-audio,-largefile} will run
265- \module {regrtest.py} with all resources except the audio and largefile
266- resources.
167+ \programopt {all}.
168+ The command \program {python regrtest.py}
169+ \programopt {-uall,-audio,-largefile} will run \module {test.regrtest}
170+ with all resources except the \programopt {audio} and
171+ \programopt {largefile} resources.
267172For a list of all resources and more command-line options, run
268- \code {python regrtest.py -h}.
173+ \program {python regrtest.py} \programopt { -h}.
269174
270175Some other ways to execute the regression tests depend on what platform the
271176tests are being executed on.
272- On \UNIX {}, you can run \code {make test} at the top-level directory
273- where Python was built.
274- On Windows, executing \code {rt.bat} from your PCBuild directory will run all
177+ On \UNIX {}, you can run \program {make} \programopt {test} at the
178+ top-level directory where Python was built.
179+ On Windows, executing \program {rt.bat} from your \file {PCBuild}
180+ directory will run all regression tests.
181+
182+
183+ \section {\module {test.test_support} ---
184+ Utility functions for tests }
185+
186+ \declaremodule [test.testsupport]{standard}{test.test_support}
187+ \modulesynopsis {Support for Python regression tests.}
188+
189+ The \module {test.test_support} module provides support for Python's
275190regression tests.
276191
192+ This module defines the following exceptions:
193+
194+ \begin {excdesc }{TestFailed}
195+ Exception to be raised when a test fails.
196+ \end {excdesc }
197+
198+ \begin {excdesc }{TestSkipped}
199+ Subclass of \exception {TestFailed}.
200+ Raised when a test is skipped.
201+ This occurs when a needed resource (such as a network connection) is not
202+ available at the time of testing.
203+ \end {excdesc }
204+
205+ \begin {excdesc }{ResourceDenied}
206+ Subclass of \exception {TestSkipped}.
207+ Raised when a resource (such as a network connection) is not available.
208+ Raised by the \function {requires()} function.
209+ \end {excdesc }
210+
211+
212+ The \module {test.test_support} module defines the following constants:
213+
214+ \begin {datadesc }{verbose}
215+ \constant {True} when verbose output is enabled.
216+ Should be checked when more detailed information is desired about a running
217+ test.
218+ \var {verbose} is set by \module {test.regrtest}.
219+ \end {datadesc }
220+
221+ \begin {datadesc }{have_unicode}
222+ \constant {True} when Unicode support is available.
223+ \end {datadesc }
224+
225+ \begin {datadesc }{is_jython}
226+ \constant {True} if the running interpreter is Jython.
227+ \end {datadesc }
228+
229+ \begin {datadesc }{TESTFN}
230+ Set to the path that a temporary file may be created at.
231+ Any temporary that is created should be closed and unlinked (removed).
232+ \end {datadesc }
233+
234+
235+ The \module {test.test_support} module defines the following functions:
236+
237+ \begin {funcdesc }{forget}{module_name}
238+ Removes the module named \var {module_name} from \code {sys.modules} and deletes
239+ any byte-compiled files of the module.
240+ \end {funcdesc }
241+
242+ \begin {funcdesc }{is_resource_enabled}{resource}
243+ Returns \constant {True} if \var {resource} is enabled and available.
244+ The list of available resources is only set when \module {test.regrtest}
245+ is executing the tests.
246+ \end {funcdesc }
247+
248+ \begin {funcdesc }{requires}{resource\optional {, msg}}
249+ Raises \exception {ResourceDenied} if \var {resource} is not available.
250+ \var {msg} is the argument to \exception {ResourceDenied} if it is raised.
251+ Always returns true if called by a function whose \code {__name__} is
252+ \code {'__main__'}.
253+ Used when tests are executed by \module {test.regrtest}.
254+ \end {funcdesc }
255+
256+ \begin {funcdesc }{findfile}{filename}
257+ Return the path to the file named \var {filename}.
258+ If no match is found \var {filename} is returned.
259+ This does not equal a failure since it could be the path to the file.
260+ \end {funcdesc }
261+
262+ \begin {funcdesc }{run_unittest}{*classes}
263+ Execute \class {unittest.TestCase} subclasses passed to the function.
264+ The function scans the classes for methods starting with the prefix
265+ \samp {test_} and executes the tests individually.
266+ This is the preferred way to execute tests.
267+ \end {funcdesc }
268+
269+ \begin {funcdesc }{run_suite}{suite\optional {, testclass}}
270+ Execute the \class {unittest.TestSuite} instance \var {suite}.
271+ The optional argument \var {testclass} accepts one of the test classes in the
272+ suite so as to print out more detailed information on where the testing suite
273+ originated from.
274+ \end {funcdesc }
0 commit comments