Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 1 | \section{\module{doctest} --- |
| 2 | Test docstrings represent reality} |
| 3 | |
| 4 | \declaremodule{standard}{doctest} |
| 5 | \moduleauthor{Tim Peters}{tim_one@users.sourceforge.net} |
| 6 | \sectionauthor{Tim Peters}{tim_one@users.sourceforge.net} |
| 7 | \sectionauthor{Moshe Zadka}{moshez@debian.org} |
| 8 | |
| 9 | \modulesynopsis{A framework for verifying examples in docstrings.} |
| 10 | |
| 11 | The \module{doctest} module searches a module's docstrings for text that looks |
| 12 | like an interactive Python session, then executes all such sessions to verify |
| 13 | they still work exactly as shown. Here's a complete but small example: |
| 14 | |
| 15 | \begin{verbatim} |
| 16 | """ |
| 17 | This is module example. |
| 18 | |
| 19 | Example supplies one function, factorial. For example, |
| 20 | |
| 21 | >>> factorial(5) |
| 22 | 120 |
| 23 | """ |
| 24 | |
| 25 | def factorial(n): |
| 26 | """Return the factorial of n, an exact integer >= 0. |
| 27 | |
| 28 | If the result is small enough to fit in an int, return an int. |
| 29 | Else return a long. |
| 30 | |
| 31 | >>> [factorial(n) for n in range(6)] |
| 32 | [1, 1, 2, 6, 24, 120] |
| 33 | >>> [factorial(long(n)) for n in range(6)] |
| 34 | [1, 1, 2, 6, 24, 120] |
| 35 | >>> factorial(30) |
| 36 | 265252859812191058636308480000000L |
| 37 | >>> factorial(30L) |
| 38 | 265252859812191058636308480000000L |
| 39 | >>> factorial(-1) |
| 40 | Traceback (most recent call last): |
| 41 | ... |
| 42 | ValueError: n must be >= 0 |
| 43 | |
| 44 | Factorials of floats are OK, but the float must be an exact integer: |
| 45 | >>> factorial(30.1) |
| 46 | Traceback (most recent call last): |
| 47 | ... |
| 48 | ValueError: n must be exact integer |
| 49 | >>> factorial(30.0) |
| 50 | 265252859812191058636308480000000L |
| 51 | |
| 52 | It must also not be ridiculously large: |
| 53 | >>> factorial(1e100) |
| 54 | Traceback (most recent call last): |
| 55 | ... |
| 56 | OverflowError: n too large |
| 57 | """ |
| 58 | |
| 59 | \end{verbatim} |
| 60 | % allow LaTeX to break here. |
| 61 | \begin{verbatim} |
| 62 | |
| 63 | import math |
| 64 | if not n >= 0: |
| 65 | raise ValueError("n must be >= 0") |
| 66 | if math.floor(n) != n: |
| 67 | raise ValueError("n must be exact integer") |
Raymond Hettinger | 92f21b1 | 2003-07-11 22:32:18 +0000 | [diff] [blame] | 68 | if n+1 == n: # catch a value like 1e300 |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 69 | raise OverflowError("n too large") |
| 70 | result = 1 |
| 71 | factor = 2 |
| 72 | while factor <= n: |
| 73 | try: |
| 74 | result *= factor |
| 75 | except OverflowError: |
| 76 | result *= long(factor) |
| 77 | factor += 1 |
| 78 | return result |
| 79 | |
| 80 | def _test(): |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 81 | import doctest |
| 82 | return doctest.testmod() |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 83 | |
| 84 | if __name__ == "__main__": |
| 85 | _test() |
| 86 | \end{verbatim} |
| 87 | |
Fred Drake | 7a6b4f0 | 2003-07-17 16:00:01 +0000 | [diff] [blame] | 88 | If you run \file{example.py} directly from the command line, |
| 89 | \module{doctest} works its magic: |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 90 | |
| 91 | \begin{verbatim} |
| 92 | $ python example.py |
| 93 | $ |
| 94 | \end{verbatim} |
| 95 | |
Fred Drake | 7a6b4f0 | 2003-07-17 16:00:01 +0000 | [diff] [blame] | 96 | There's no output! That's normal, and it means all the examples |
| 97 | worked. Pass \programopt{-v} to the script, and \module{doctest} |
| 98 | prints a detailed log of what it's trying, and prints a summary at the |
| 99 | end: |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 100 | |
| 101 | \begin{verbatim} |
| 102 | $ python example.py -v |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 103 | Trying: factorial(5) |
| 104 | Expecting: 120 |
| 105 | ok |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 106 | Trying: [factorial(n) for n in range(6)] |
| 107 | Expecting: [1, 1, 2, 6, 24, 120] |
| 108 | ok |
| 109 | Trying: [factorial(long(n)) for n in range(6)] |
| 110 | Expecting: [1, 1, 2, 6, 24, 120] |
Tim Peters | 41a65ea | 2004-08-13 03:55:05 +0000 | [diff] [blame^] | 111 | ok |
| 112 | \end{verbatim} |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 113 | |
| 114 | And so on, eventually ending with: |
| 115 | |
| 116 | \begin{verbatim} |
| 117 | Trying: factorial(1e100) |
| 118 | Expecting: |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 119 | Traceback (most recent call last): |
| 120 | ... |
| 121 | OverflowError: n too large |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 122 | ok |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 123 | 2 items passed all tests: |
| 124 | 1 tests in example |
| 125 | 8 tests in example.factorial |
| 126 | 9 tests in 2 items. |
| 127 | 9 passed and 0 failed. |
| 128 | Test passed. |
| 129 | $ |
| 130 | \end{verbatim} |
| 131 | |
Fred Drake | 7a6b4f0 | 2003-07-17 16:00:01 +0000 | [diff] [blame] | 132 | That's all you need to know to start making productive use of |
Tim Peters | 41a65ea | 2004-08-13 03:55:05 +0000 | [diff] [blame^] | 133 | \module{doctest}! Jump in. The following sections provide full |
| 134 | details. Note that there are many examples of doctests in |
| 135 | the standard Python test suite and libraries. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 136 | |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 137 | \subsection{Simple Usage} |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 138 | |
Tim Peters | 41a65ea | 2004-08-13 03:55:05 +0000 | [diff] [blame^] | 139 | The simplest way to start using doctest (but not necessarily the way |
| 140 | you'll continue to do it) is to end each module \module{M} with: |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 141 | |
| 142 | \begin{verbatim} |
| 143 | def _test(): |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 144 | import doctest |
| 145 | return doctest.testmod() |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 146 | |
| 147 | if __name__ == "__main__": |
| 148 | _test() |
| 149 | \end{verbatim} |
| 150 | |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 151 | \module{doctest} then examines docstrings in the module calling |
Tim Peters | 41a65ea | 2004-08-13 03:55:05 +0000 | [diff] [blame^] | 152 | \function{testmod()}. |
Martin v. Löwis | 4581cfa | 2002-11-22 08:23:09 +0000 | [diff] [blame] | 153 | |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 154 | Running the module as a script causes the examples in the docstrings |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 155 | to get executed and verified: |
| 156 | |
| 157 | \begin{verbatim} |
| 158 | python M.py |
| 159 | \end{verbatim} |
| 160 | |
| 161 | This won't display anything unless an example fails, in which case the |
| 162 | failing example(s) and the cause(s) of the failure(s) are printed to stdout, |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 163 | and the final line of output is |
Tim Peters | 2603960 | 2004-08-13 01:49:12 +0000 | [diff] [blame] | 164 | \samp{'***Test Failed*** \var{N} failures.'}, where \var{N} is the |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 165 | number of examples that failed. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 166 | |
Fred Drake | 7eb1463 | 2001-02-17 17:32:41 +0000 | [diff] [blame] | 167 | Run it with the \programopt{-v} switch instead: |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 168 | |
| 169 | \begin{verbatim} |
| 170 | python M.py -v |
| 171 | \end{verbatim} |
| 172 | |
Fred Drake | 8836e56 | 2003-07-17 15:22:47 +0000 | [diff] [blame] | 173 | and a detailed report of all examples tried is printed to standard |
| 174 | output, along with assorted summaries at the end. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 175 | |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 176 | You can force verbose mode by passing \code{verbose=True} to |
Fred Drake | 5d2f515 | 2003-06-28 03:09:06 +0000 | [diff] [blame] | 177 | \function{testmod()}, or |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 178 | prohibit it by passing \code{verbose=False}. In either of those cases, |
Fred Drake | 5d2f515 | 2003-06-28 03:09:06 +0000 | [diff] [blame] | 179 | \code{sys.argv} is not examined by \function{testmod()}. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 180 | |
Fred Drake | 5d2f515 | 2003-06-28 03:09:06 +0000 | [diff] [blame] | 181 | In any case, \function{testmod()} returns a 2-tuple of ints \code{(\var{f}, |
Fred Drake | 7eb1463 | 2001-02-17 17:32:41 +0000 | [diff] [blame] | 182 | \var{t})}, where \var{f} is the number of docstring examples that |
| 183 | failed and \var{t} is the total number of docstring examples |
| 184 | attempted. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 185 | |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 186 | \begin{funcdesc}{testmod}{\optional{m}\optional{, name}\optional{, |
| 187 | globs}\optional{, verbose}\optional{, |
| 188 | isprivate}\optional{, report}\optional{, |
| 189 | optionflags}\optional{, extraglobs}\optional{, |
| 190 | raise_on_error}} |
| 191 | |
| 192 | All arguments are optional, and all except for \var{m} should be |
| 193 | specified in keyword form. |
| 194 | |
| 195 | Test examples in docstrings in functions and classes reachable |
| 196 | from module \var{m} (or the current module if \var{m} is not supplied |
| 197 | or is \code{None}), starting with \code{\var{m}.__doc__}. |
| 198 | |
| 199 | Also test examples reachable from dict \code{\var{m}.__test__}, if it |
| 200 | exists and is not \code{None}. \code{\var{m}.__test__} maps |
| 201 | names (strings) to functions, classes and strings; function and class |
| 202 | docstrings are searched for examples; strings are searched directly, |
| 203 | as if they were docstrings. |
| 204 | |
| 205 | Only docstrings attached to objects belonging to module \var{m} are |
| 206 | searched. |
| 207 | |
Tim Peters | 2603960 | 2004-08-13 01:49:12 +0000 | [diff] [blame] | 208 | Return \samp{(\var{failure_count}, \var{test_count})}. |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 209 | |
| 210 | Optional argument \var{name} gives the name of the module; by default, |
| 211 | or if \code{None}, \code{\var{m}.__name__} is used. |
| 212 | |
| 213 | Optional argument \var{globs} gives a dict to be used as the globals |
| 214 | when executing examples; by default, or if \code{None}, |
| 215 | \code{\var{m}.__dict__} is used. A new shallow copy of this dict is |
| 216 | created for each docstring with examples, so that each docstring's |
| 217 | examples start with a clean slate. |
| 218 | |
Tim Peters | 8a3b69c | 2004-08-12 22:31:25 +0000 | [diff] [blame] | 219 | Optional argument \var{extraglobs} gives a dict merged into the |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 220 | globals used to execute examples. This works like |
| 221 | \method{dict.update()}: if \var{globs} and \var{extraglobs} have a |
| 222 | common key, the associated value in \var{extraglobs} appears in the |
| 223 | combined dict. By default, or if \code{None}, no extra globals are |
| 224 | used. This is an advanced feature that allows parameterization of |
| 225 | doctests. For example, a doctest can be written for a base class, using |
| 226 | a generic name for the class, then reused to test any number of |
| 227 | subclasses by passing an \var{extraglobs} dict mapping the generic |
| 228 | name to the subclass to be tested. |
| 229 | |
| 230 | Optional argument \var{verbose} prints lots of stuff if true, and prints |
| 231 | only failures if false; by default, or if \code{None}, it's true |
Tim Peters | 2603960 | 2004-08-13 01:49:12 +0000 | [diff] [blame] | 232 | if and only if \code{'-v'} is in \code{sys.argv}. |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 233 | |
| 234 | Optional argument \var{report} prints a summary at the end when true, |
| 235 | else prints nothing at the end. In verbose mode, the summary is |
| 236 | detailed, else the summary is very brief (in fact, empty if all tests |
| 237 | passed). |
| 238 | |
Tim Peters | 8a3b69c | 2004-08-12 22:31:25 +0000 | [diff] [blame] | 239 | Optional argument \var{optionflags} or's together option flags. See |
| 240 | see section \ref{doctest-options}. |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 241 | |
| 242 | Optional argument \var{raise_on_error} defaults to false. If true, |
| 243 | an exception is raised upon the first failure or unexpected exception |
| 244 | in an example. This allows failures to be post-mortem debugged. |
| 245 | Default behavior is to continue running examples. |
| 246 | |
| 247 | Optional argument \var{isprivate} specifies a function used to |
| 248 | determine whether a name is private. The default function treats |
| 249 | all names as public. \var{isprivate} can be set to |
Tim Peters | 2603960 | 2004-08-13 01:49:12 +0000 | [diff] [blame] | 250 | \code{doctest.is_private} to skip over names that are |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 251 | private according to Python's underscore naming convention. |
| 252 | \deprecated{2.4}{\var{isprivate} was a stupid idea -- don't use it. |
| 253 | If you need to skip tests based on name, filter the list returned by |
Fred Drake | 9d92d5a | 2004-08-10 15:41:03 +0000 | [diff] [blame] | 254 | \code{DocTestFinder.find()} instead.} |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 255 | |
| 256 | % """ [XX] This is no longer true: |
| 257 | % Advanced tomfoolery: testmod runs methods of a local instance of |
| 258 | % class doctest.Tester, then merges the results into (or creates) |
| 259 | % global Tester instance doctest.master. Methods of doctest.master |
| 260 | % can be called directly too, if you want to do something unusual. |
| 261 | % Passing report=0 to testmod is especially useful then, to delay |
| 262 | % displaying a summary. Invoke doctest.master.summarize(verbose) |
| 263 | % when you're done fiddling. |
| 264 | |
| 265 | \versionchanged[The parameter \var{optionflags} was added]{2.3} |
| 266 | |
Tim Peters | c2388a2 | 2004-08-10 01:41:28 +0000 | [diff] [blame] | 267 | \versionchanged[The parameters \var{extraglobs} and \var{raise_on_error} |
| 268 | were added]{2.4} |
| 269 | \end{funcdesc} |
| 270 | |
| 271 | |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 272 | \subsection{Which Docstrings Are Examined?} |
| 273 | |
Tim Peters | 8a3b69c | 2004-08-12 22:31:25 +0000 | [diff] [blame] | 274 | The module docstring, and all function, class and method docstrings are |
| 275 | searched. Objects imported into the module are not searched. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 276 | |
Fred Drake | 7eb1463 | 2001-02-17 17:32:41 +0000 | [diff] [blame] | 277 | In addition, if \code{M.__test__} exists and "is true", it must be a |
| 278 | dict, and each entry maps a (string) name to a function object, class |
| 279 | object, or string. Function and class object docstrings found from |
Tim Peters | 8a3b69c | 2004-08-12 22:31:25 +0000 | [diff] [blame] | 280 | \code{M.__test__} are searched, and strings are treated as if they |
| 281 | were docstrings. In output, a key \code{K} in \code{M.__test__} appears |
| 282 | with name |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 283 | |
| 284 | \begin{verbatim} |
Fred Drake | 8836e56 | 2003-07-17 15:22:47 +0000 | [diff] [blame] | 285 | <name of M>.__test__.K |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 286 | \end{verbatim} |
| 287 | |
| 288 | Any classes found are recursively searched similarly, to test docstrings in |
Tim Peters | 8a3b69c | 2004-08-12 22:31:25 +0000 | [diff] [blame] | 289 | their contained methods and nested classes. |
| 290 | |
| 291 | \versionchanged[A "private name" concept is deprecated and no longer |
Tim Peters | 2603960 | 2004-08-13 01:49:12 +0000 | [diff] [blame] | 292 | documented]{2.4} |
Tim Peters | 8a3b69c | 2004-08-12 22:31:25 +0000 | [diff] [blame] | 293 | |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 294 | |
| 295 | \subsection{What's the Execution Context?} |
| 296 | |
Tim Peters | 41a65ea | 2004-08-13 03:55:05 +0000 | [diff] [blame^] | 297 | By default, each time \function{testmod()} finds a docstring to test, it |
| 298 | uses a \emph{shallow copy} of \module{M}'s globals, so that running tests |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 299 | doesn't change the module's real globals, and so that one test in |
| 300 | \module{M} can't leave behind crumbs that accidentally allow another test |
| 301 | to work. This means examples can freely use any names defined at top-level |
Tim Peters | 0481d24 | 2001-10-02 21:01:22 +0000 | [diff] [blame] | 302 | in \module{M}, and names defined earlier in the docstring being run. |
Tim Peters | 41a65ea | 2004-08-13 03:55:05 +0000 | [diff] [blame^] | 303 | Examples cannot see names defined in other docstrings. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 304 | |
| 305 | You can force use of your own dict as the execution context by passing |
Tim Peters | 41a65ea | 2004-08-13 03:55:05 +0000 | [diff] [blame^] | 306 | \code{globs=your_dict} to \function{testmod()} instead. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 307 | |
| 308 | \subsection{What About Exceptions?} |
| 309 | |
Tim Peters | 41a65ea | 2004-08-13 03:55:05 +0000 | [diff] [blame^] | 310 | No problem: just paste in the expected traceback. Since |
| 311 | tracebacks contain details that are likely to change |
| 312 | rapidly (for example, exact file paths and line numbers), this is one |
| 313 | case where doctest works hard to be flexible in what it accepts. |
| 314 | This makes the full story involved, but you really don't have |
| 315 | to remember much. Simple example: |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 316 | |
| 317 | \begin{verbatim} |
Fred Drake | 19f3c52 | 2001-02-22 23:15:05 +0000 | [diff] [blame] | 318 | >>> [1, 2, 3].remove(42) |
| 319 | Traceback (most recent call last): |
| 320 | File "<stdin>", line 1, in ? |
| 321 | ValueError: list.remove(x): x not in list |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 322 | \end{verbatim} |
| 323 | |
Tim Peters | 41a65ea | 2004-08-13 03:55:05 +0000 | [diff] [blame^] | 324 | That doctest succeeds if, and only if, \exception{ValueError} is raised, |
| 325 | with the \samp{list.remove(x): x not in list} detail as shown. |
| 326 | |
| 327 | The expected output for an exception is divided into four parts. |
| 328 | First, an example may produce some normal output before an exception |
| 329 | is raised, although that's unusual. The "normal output" is taken to |
| 330 | be everything until the first "Traceback" line, and is usually an |
| 331 | empty string. Next, the traceback line must be one of these two, and |
| 332 | indented the same as the first line in the example: |
| 333 | |
| 334 | \begin{verbatim} |
| 335 | Traceback (most recent call last): |
| 336 | Traceback (innermost last): |
| 337 | \end{verbatim} |
| 338 | |
| 339 | The most interesting part is the last part: the line(s) starting with the |
| 340 | exception type and detail. This is usually the last line of a traceback, |
| 341 | but can extend across any number of lines. After the "Traceback" line, |
| 342 | doctest simply ignores everything until the first line indented the same as |
| 343 | the first line of the example, \emph{and} starting with an alphanumeric |
| 344 | character. This example illustrates the complexities that are possible: |
| 345 | |
| 346 | \begin{verbatim} |
| 347 | >>> print 1, 2; raise ValueError('printed 1\nand 2\n but not 3') |
| 348 | 1 2 |
| 349 | Traceback (most recent call last): |
| 350 | ... indented the same, but doesn't start with an alphanumeric |
| 351 | not indented the same, so ignored too |
| 352 | File "/Python23/lib/doctest.py", line 442, in _run_examples_inner |
| 353 | compileflags, 1) in globs |
| 354 | File "<string>", line 1, in ? # and all these are ignored |
| 355 | ValueError: printed 1 |
| 356 | and 2 |
| 357 | but not 3 |
| 358 | \end{verbatim} |
| 359 | |
| 360 | The first (\samp{1 2}) and last three (starting with |
| 361 | \exception{ValueError}) lines are compared, and the rest are ignored. |
| 362 | |
| 363 | Best practice is to omit the ``File'' lines, unless they add |
| 364 | significant documentation value to the example. So the example above |
| 365 | is probably better as: |
| 366 | |
| 367 | \begin{verbatim} |
| 368 | >>> print 1, 2; raise ValueError('printed 1\nand 2\n but not 3') |
| 369 | 1 2 |
| 370 | Traceback (most recent call last): |
| 371 | ... |
| 372 | ValueError: printed 1 |
| 373 | and 2 |
| 374 | but not 3 |
| 375 | \end{verbatim} |
| 376 | |
| 377 | Note the tracebacks are treated very specially. In particular, in the |
| 378 | rewritten example, the use of \samp{...} is independent of doctest's |
| 379 | \constant{ELLIPSIS} option. The ellipsis in that example could |
| 380 | be left out, or could just as well be three (or three hundred) commas. |
| 381 | |
| 382 | \versionchanged[The abilities to check both normal output and an |
| 383 | exception in a single example, and to have a multi-line |
| 384 | exception detail, were added]{2.4} |
| 385 | |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 386 | |
Tim Peters | 8a3b69c | 2004-08-12 22:31:25 +0000 | [diff] [blame] | 387 | \subsection{Option Flags and Directive Names\label{doctest-options}} |
| 388 | |
| 389 | A number of option flags control various aspects of doctest's behavior. |
| 390 | Symbolic names for the flags are supplied as module constants, which |
| 391 | can be or'ed together and passed to various functions. The names can |
| 392 | also be used in doctest directives. |
| 393 | |
| 394 | \begin{datadesc}{DONT_ACCEPT_TRUE_FOR_1} |
| 395 | By default, if an expected output block contains just \code{1}, |
| 396 | an actual output block containing just \code{1} or just |
| 397 | \code{True} is considered to be a match, and similarly for \code{0} |
| 398 | versus \code{False}. When \constant{DONT_ACCEPT_TRUE_FOR_1} is |
| 399 | specified, neither substitution is allowed. The default behavior |
| 400 | caters to that Python changed the return type of many functions |
| 401 | from integer to boolean; doctests expecting "little integer" |
| 402 | output still work in these cases. This option will probably go |
| 403 | away, but not for several years. |
| 404 | \end{datadesc} |
| 405 | |
| 406 | \begin{datadesc}{DONT_ACCEPT_BLANKLINE} |
| 407 | By default, if an expected output block contains a line |
| 408 | containing only the string \code{<BLANKLINE>}, then that line |
| 409 | will match a blank line in the actual output. Because a |
| 410 | genuinely blank line delimits the expected output, this is |
| 411 | the only way to communicate that a blank line is expected. When |
| 412 | \constant{DONT_ACCEPT_BLANKLINE} is specified, this substitution |
| 413 | is not allowed. |
| 414 | \end{datadesc} |
| 415 | |
| 416 | \begin{datadesc}{NORMALIZE_WHITESPACE} |
| 417 | When specified, all sequences of whitespace (blanks and newlines) are |
| 418 | treated as equal. Any sequence of whitespace within the expected |
| 419 | output will match any sequence of whitespace within the actual output. |
| 420 | By default, whitespace must match exactly. |
| 421 | \constant{NORMALIZE_WHITESPACE} is especially useful when a line |
| 422 | of expected output is very long, and you want to wrap it across |
| 423 | multiple lines in your source. |
| 424 | \end{datadesc} |
| 425 | |
| 426 | \begin{datadesc}{ELLIPSIS} |
| 427 | When specified, an ellipsis marker (\code{...}) in the expected output |
| 428 | can match any substring in the actual output. This includes |
| 429 | substrings that span line boundaries, so it's best to keep usage of |
| 430 | this simple. Complicated uses can lead to the same kinds of |
Tim Peters | 2603960 | 2004-08-13 01:49:12 +0000 | [diff] [blame] | 431 | surprises that \regexp{.*} is prone to in regular expressions. |
Tim Peters | 8a3b69c | 2004-08-12 22:31:25 +0000 | [diff] [blame] | 432 | \end{datadesc} |
| 433 | |
| 434 | \begin{datadesc}{UNIFIED_DIFF} |
| 435 | When specified, failures that involve multi-line expected and |
| 436 | actual outputs are displayed using a unified diff. |
| 437 | \end{datadesc} |
| 438 | |
| 439 | \begin{datadesc}{CONTEXT_DIFF} |
| 440 | When specified, failures that involve multi-line expected and |
| 441 | actual outputs will be displayed using a context diff. |
| 442 | \end{datadesc} |
| 443 | |
| 444 | |
| 445 | \versionchanged[Constants \constant{DONT_ACCEPT_BLANKLINE}, |
| 446 | \constant{NORMALIZE_WHITESPACE}, \constant{ELLIPSIS}, |
| 447 | \constant{UNIFIED_DIFF}, and \constant{CONTEXT_DIFF} |
| 448 | were added, and \code{<BLANKLINE>} in expected output matches |
Tim Peters | 2603960 | 2004-08-13 01:49:12 +0000 | [diff] [blame] | 449 | an empty line in actual output by default]{2.4} |
Tim Peters | 8a3b69c | 2004-08-12 22:31:25 +0000 | [diff] [blame] | 450 | |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 451 | \subsection{Advanced Usage} |
| 452 | |
Raymond Hettinger | 92f21b1 | 2003-07-11 22:32:18 +0000 | [diff] [blame] | 453 | Several module level functions are available for controlling how doctests |
| 454 | are run. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 455 | |
Raymond Hettinger | 92f21b1 | 2003-07-11 22:32:18 +0000 | [diff] [blame] | 456 | \begin{funcdesc}{debug}{module, name} |
| 457 | Debug a single docstring containing doctests. |
| 458 | |
| 459 | Provide the \var{module} (or dotted name of the module) containing the |
| 460 | docstring to be debugged and the \var{name} (within the module) of the |
| 461 | object with the docstring to be debugged. |
| 462 | |
| 463 | The doctest examples are extracted (see function \function{testsource()}), |
| 464 | and written to a temporary file. The Python debugger, \refmodule{pdb}, |
Fred Drake | 8836e56 | 2003-07-17 15:22:47 +0000 | [diff] [blame] | 465 | is then invoked on that file. |
Raymond Hettinger | 92f21b1 | 2003-07-11 22:32:18 +0000 | [diff] [blame] | 466 | \versionadded{2.3} |
| 467 | \end{funcdesc} |
| 468 | |
| 469 | \begin{funcdesc}{testmod}{} |
| 470 | This function provides the most basic interface to the doctests. |
| 471 | It creates a local instance of class \class{Tester}, runs appropriate |
| 472 | methods of that class, and merges the results into the global \class{Tester} |
| 473 | instance, \code{master}. |
| 474 | |
| 475 | To get finer control than \function{testmod()} offers, create an instance |
Fred Drake | 8836e56 | 2003-07-17 15:22:47 +0000 | [diff] [blame] | 476 | of \class{Tester} with custom policies, or run methods of \code{master} |
Raymond Hettinger | 92f21b1 | 2003-07-11 22:32:18 +0000 | [diff] [blame] | 477 | directly. See \code{Tester.__doc__} for details. |
| 478 | \end{funcdesc} |
| 479 | |
| 480 | \begin{funcdesc}{testsource}{module, name} |
| 481 | Extract the doctest examples from a docstring. |
| 482 | |
| 483 | Provide the \var{module} (or dotted name of the module) containing the |
| 484 | tests to be extracted and the \var{name} (within the module) of the object |
| 485 | with the docstring containing the tests to be extracted. |
| 486 | |
| 487 | The doctest examples are returned as a string containing Python |
| 488 | code. The expected output blocks in the examples are converted |
| 489 | to Python comments. |
| 490 | \versionadded{2.3} |
| 491 | \end{funcdesc} |
| 492 | |
| 493 | \begin{funcdesc}{DocTestSuite}{\optional{module}} |
Fred Drake | 7a6b4f0 | 2003-07-17 16:00:01 +0000 | [diff] [blame] | 494 | Convert doctest tests for a module to a |
| 495 | \class{\refmodule{unittest}.TestSuite}. |
Raymond Hettinger | 92f21b1 | 2003-07-11 22:32:18 +0000 | [diff] [blame] | 496 | |
| 497 | The returned \class{TestSuite} is to be run by the unittest framework |
| 498 | and runs each doctest in the module. If any of the doctests fail, |
| 499 | then the synthesized unit test fails, and a \exception{DocTestTestFailure} |
| 500 | exception is raised showing the name of the file containing the test and a |
| 501 | (sometimes approximate) line number. |
| 502 | |
| 503 | The optional \var{module} argument provides the module to be tested. It |
| 504 | can be a module object or a (possibly dotted) module name. If not |
Fred Drake | 8836e56 | 2003-07-17 15:22:47 +0000 | [diff] [blame] | 505 | specified, the module calling this function is used. |
Raymond Hettinger | 92f21b1 | 2003-07-11 22:32:18 +0000 | [diff] [blame] | 506 | |
| 507 | Example using one of the many ways that the \refmodule{unittest} module |
| 508 | can use a \class{TestSuite}: |
| 509 | |
| 510 | \begin{verbatim} |
| 511 | import unittest |
| 512 | import doctest |
| 513 | import my_module_with_doctests |
| 514 | |
| 515 | suite = doctest.DocTestSuite(my_module_with_doctests) |
| 516 | runner = unittest.TextTestRunner() |
| 517 | runner.run(suite) |
| 518 | \end{verbatim} |
| 519 | |
| 520 | \versionadded{2.3} |
Fred Drake | 8836e56 | 2003-07-17 15:22:47 +0000 | [diff] [blame] | 521 | \warning{This function does not currently search \code{M.__test__} |
Raymond Hettinger | 943277e | 2003-07-17 14:47:12 +0000 | [diff] [blame] | 522 | and its search technique does not exactly match \function{testmod()} in |
| 523 | every detail. Future versions will bring the two into convergence.} |
Raymond Hettinger | 92f21b1 | 2003-07-11 22:32:18 +0000 | [diff] [blame] | 524 | \end{funcdesc} |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 525 | |
| 526 | |
| 527 | \subsection{How are Docstring Examples Recognized?} |
| 528 | |
Fred Drake | 7a6b4f0 | 2003-07-17 16:00:01 +0000 | [diff] [blame] | 529 | In most cases a copy-and-paste of an interactive console session works |
| 530 | fine---just make sure the leading whitespace is rigidly consistent |
| 531 | (you can mix tabs and spaces if you're too lazy to do it right, but |
| 532 | \module{doctest} is not in the business of guessing what you think a tab |
| 533 | means). |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 534 | |
| 535 | \begin{verbatim} |
Fred Drake | 19f3c52 | 2001-02-22 23:15:05 +0000 | [diff] [blame] | 536 | >>> # comments are ignored |
| 537 | >>> x = 12 |
| 538 | >>> x |
| 539 | 12 |
| 540 | >>> if x == 13: |
| 541 | ... print "yes" |
| 542 | ... else: |
| 543 | ... print "no" |
| 544 | ... print "NO" |
| 545 | ... print "NO!!!" |
| 546 | ... |
| 547 | no |
| 548 | NO |
| 549 | NO!!! |
| 550 | >>> |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 551 | \end{verbatim} |
| 552 | |
Fred Drake | 19f3c52 | 2001-02-22 23:15:05 +0000 | [diff] [blame] | 553 | Any expected output must immediately follow the final |
| 554 | \code{'>\code{>}>~'} or \code{'...~'} line containing the code, and |
| 555 | the expected output (if any) extends to the next \code{'>\code{>}>~'} |
| 556 | or all-whitespace line. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 557 | |
| 558 | The fine print: |
| 559 | |
| 560 | \begin{itemize} |
| 561 | |
| 562 | \item Expected output cannot contain an all-whitespace line, since such a |
| 563 | line is taken to signal the end of expected output. |
| 564 | |
| 565 | \item Output to stdout is captured, but not output to stderr (exception |
| 566 | tracebacks are captured via a different means). |
| 567 | |
Martin v. Löwis | 92816de | 2004-05-31 19:01:00 +0000 | [diff] [blame] | 568 | \item If you continue a line via backslashing in an interactive session, |
| 569 | or for any other reason use a backslash, you should use a raw |
| 570 | docstring, which will preserve your backslahses exactly as you type |
| 571 | them: |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 572 | |
| 573 | \begin{verbatim} |
Tim Peters | 336689b | 2004-07-23 02:48:24 +0000 | [diff] [blame] | 574 | >>> def f(x): |
Martin v. Löwis | 92816de | 2004-05-31 19:01:00 +0000 | [diff] [blame] | 575 | ... r'''Backslashes in a raw docstring: m\n''' |
| 576 | >>> print f.__doc__ |
| 577 | Backslashes in a raw docstring: m\n |
| 578 | \end{verbatim} |
Tim Peters | 336689b | 2004-07-23 02:48:24 +0000 | [diff] [blame] | 579 | |
Martin v. Löwis | 92816de | 2004-05-31 19:01:00 +0000 | [diff] [blame] | 580 | Otherwise, the backslash will be interpreted as part of the string. |
| 581 | E.g., the "\textbackslash" above would be interpreted as a newline |
| 582 | character. Alternatively, you can double each backslash in the |
| 583 | doctest version (and not use a raw string): |
| 584 | |
| 585 | \begin{verbatim} |
Tim Peters | 336689b | 2004-07-23 02:48:24 +0000 | [diff] [blame] | 586 | >>> def f(x): |
Martin v. Löwis | 92816de | 2004-05-31 19:01:00 +0000 | [diff] [blame] | 587 | ... '''Backslashes in a raw docstring: m\\n''' |
| 588 | >>> print f.__doc__ |
| 589 | Backslashes in a raw docstring: m\n |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 590 | \end{verbatim} |
| 591 | |
Tim Peters | f0768c8 | 2001-02-20 10:57:30 +0000 | [diff] [blame] | 592 | \item The starting column doesn't matter: |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 593 | |
| 594 | \begin{verbatim} |
Tim Peters | c4089d8 | 2001-02-17 18:03:25 +0000 | [diff] [blame] | 595 | >>> assert "Easy!" |
| 596 | >>> import math |
| 597 | >>> math.floor(1.9) |
| 598 | 1.0 |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 599 | \end{verbatim} |
| 600 | |
Fred Drake | 19f3c52 | 2001-02-22 23:15:05 +0000 | [diff] [blame] | 601 | and as many leading whitespace characters are stripped from the |
| 602 | expected output as appeared in the initial \code{'>\code{>}>~'} line |
| 603 | that triggered it. |
Fred Drake | 7eb1463 | 2001-02-17 17:32:41 +0000 | [diff] [blame] | 604 | \end{itemize} |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 605 | |
| 606 | \subsection{Warnings} |
| 607 | |
| 608 | \begin{enumerate} |
| 609 | |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 610 | \item \module{doctest} is serious about requiring exact matches in expected |
| 611 | output. If even a single character doesn't match, the test fails. This |
| 612 | will probably surprise you a few times, as you learn exactly what Python |
| 613 | does and doesn't guarantee about output. For example, when printing a |
| 614 | dict, Python doesn't guarantee that the key-value pairs will be printed |
| 615 | in any particular order, so a test like |
| 616 | |
| 617 | % Hey! What happened to Monty Python examples? |
Tim Peters | f0768c8 | 2001-02-20 10:57:30 +0000 | [diff] [blame] | 618 | % Tim: ask Guido -- it's his example! |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 619 | \begin{verbatim} |
Fred Drake | 19f3c52 | 2001-02-22 23:15:05 +0000 | [diff] [blame] | 620 | >>> foo() |
| 621 | {"Hermione": "hippogryph", "Harry": "broomstick"} |
| 622 | >>> |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 623 | \end{verbatim} |
| 624 | |
| 625 | is vulnerable! One workaround is to do |
| 626 | |
| 627 | \begin{verbatim} |
Fred Drake | 19f3c52 | 2001-02-22 23:15:05 +0000 | [diff] [blame] | 628 | >>> foo() == {"Hermione": "hippogryph", "Harry": "broomstick"} |
Martin v. Löwis | ccabed3 | 2003-11-27 19:48:03 +0000 | [diff] [blame] | 629 | True |
Fred Drake | 19f3c52 | 2001-02-22 23:15:05 +0000 | [diff] [blame] | 630 | >>> |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 631 | \end{verbatim} |
| 632 | |
| 633 | instead. Another is to do |
| 634 | |
| 635 | \begin{verbatim} |
Fred Drake | 19f3c52 | 2001-02-22 23:15:05 +0000 | [diff] [blame] | 636 | >>> d = foo().items() |
| 637 | >>> d.sort() |
| 638 | >>> d |
| 639 | [('Harry', 'broomstick'), ('Hermione', 'hippogryph')] |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 640 | \end{verbatim} |
| 641 | |
| 642 | There are others, but you get the idea. |
| 643 | |
| 644 | Another bad idea is to print things that embed an object address, like |
| 645 | |
| 646 | \begin{verbatim} |
Fred Drake | 19f3c52 | 2001-02-22 23:15:05 +0000 | [diff] [blame] | 647 | >>> id(1.0) # certain to fail some of the time |
| 648 | 7948648 |
| 649 | >>> |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 650 | \end{verbatim} |
| 651 | |
| 652 | Floating-point numbers are also subject to small output variations across |
| 653 | platforms, because Python defers to the platform C library for float |
| 654 | formatting, and C libraries vary widely in quality here. |
| 655 | |
| 656 | \begin{verbatim} |
Fred Drake | 19f3c52 | 2001-02-22 23:15:05 +0000 | [diff] [blame] | 657 | >>> 1./7 # risky |
| 658 | 0.14285714285714285 |
| 659 | >>> print 1./7 # safer |
| 660 | 0.142857142857 |
| 661 | >>> print round(1./7, 6) # much safer |
| 662 | 0.142857 |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 663 | \end{verbatim} |
| 664 | |
| 665 | Numbers of the form \code{I/2.**J} are safe across all platforms, and I |
| 666 | often contrive doctest examples to produce numbers of that form: |
| 667 | |
| 668 | \begin{verbatim} |
Fred Drake | 19f3c52 | 2001-02-22 23:15:05 +0000 | [diff] [blame] | 669 | >>> 3./4 # utterly safe |
| 670 | 0.75 |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 671 | \end{verbatim} |
| 672 | |
| 673 | Simple fractions are also easier for people to understand, and that makes |
| 674 | for better documentation. |
| 675 | |
Skip Montanaro | 1dc98c4 | 2001-06-08 14:40:28 +0000 | [diff] [blame] | 676 | \item Be careful if you have code that must only execute once. |
| 677 | |
| 678 | If you have module-level code that must only execute once, a more foolproof |
Fred Drake | c115835 | 2001-06-11 14:55:01 +0000 | [diff] [blame] | 679 | definition of \function{_test()} is |
Skip Montanaro | 1dc98c4 | 2001-06-08 14:40:28 +0000 | [diff] [blame] | 680 | |
| 681 | \begin{verbatim} |
| 682 | def _test(): |
| 683 | import doctest, sys |
Martin v. Löwis | 4581cfa | 2002-11-22 08:23:09 +0000 | [diff] [blame] | 684 | doctest.testmod() |
Skip Montanaro | 1dc98c4 | 2001-06-08 14:40:28 +0000 | [diff] [blame] | 685 | \end{verbatim} |
Tim Peters | 6ebe61f | 2003-06-27 20:48:05 +0000 | [diff] [blame] | 686 | |
| 687 | \item WYSIWYG isn't always the case, starting in Python 2.3. The |
Fred Drake | 5d2f515 | 2003-06-28 03:09:06 +0000 | [diff] [blame] | 688 | string form of boolean results changed from \code{'0'} and |
| 689 | \code{'1'} to \code{'False'} and \code{'True'} in Python 2.3. |
Tim Peters | 6ebe61f | 2003-06-27 20:48:05 +0000 | [diff] [blame] | 690 | This makes it clumsy to write a doctest showing boolean results that |
| 691 | passes under multiple versions of Python. In Python 2.3, by default, |
| 692 | and as a special case, if an expected output block consists solely |
Fred Drake | 5d2f515 | 2003-06-28 03:09:06 +0000 | [diff] [blame] | 693 | of \code{'0'} and the actual output block consists solely of |
| 694 | \code{'False'}, that's accepted as an exact match, and similarly for |
| 695 | \code{'1'} versus \code{'True'}. This behavior can be turned off by |
Tim Peters | 6ebe61f | 2003-06-27 20:48:05 +0000 | [diff] [blame] | 696 | passing the new (in 2.3) module constant |
| 697 | \constant{DONT_ACCEPT_TRUE_FOR_1} as the value of \function{testmod()}'s |
| 698 | new (in 2.3) optional \var{optionflags} argument. Some years after |
| 699 | the integer spellings of booleans are history, this hack will |
| 700 | probably be removed again. |
| 701 | |
Fred Drake | c115835 | 2001-06-11 14:55:01 +0000 | [diff] [blame] | 702 | \end{enumerate} |
| 703 | |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 704 | |
| 705 | \subsection{Soapbox} |
| 706 | |
Fred Drake | 7a6b4f0 | 2003-07-17 16:00:01 +0000 | [diff] [blame] | 707 | The first word in ``doctest'' is ``doc,'' and that's why the author |
| 708 | wrote \refmodule{doctest}: to keep documentation up to date. It so |
| 709 | happens that \refmodule{doctest} makes a pleasant unit testing |
| 710 | environment, but that's not its primary purpose. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 711 | |
Fred Drake | 7a6b4f0 | 2003-07-17 16:00:01 +0000 | [diff] [blame] | 712 | Choose docstring examples with care. There's an art to this that |
| 713 | needs to be learned---it may not be natural at first. Examples should |
| 714 | add genuine value to the documentation. A good example can often be |
| 715 | worth many words. If possible, show just a few normal cases, show |
| 716 | endcases, show interesting subtle cases, and show an example of each |
| 717 | kind of exception that can be raised. You're probably testing for |
| 718 | endcases and subtle cases anyway in an interactive shell: |
| 719 | \refmodule{doctest} wants to make it as easy as possible to capture |
| 720 | those sessions, and will verify they continue to work as designed |
| 721 | forever after. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 722 | |
Fred Drake | 7a6b4f0 | 2003-07-17 16:00:01 +0000 | [diff] [blame] | 723 | If done with care, the examples will be invaluable for your users, and |
| 724 | will pay back the time it takes to collect them many times over as the |
| 725 | years go by and things change. I'm still amazed at how often one of |
| 726 | my \refmodule{doctest} examples stops working after a ``harmless'' |
| 727 | change. |
Tim Peters | 7688229 | 2001-02-17 05:58:44 +0000 | [diff] [blame] | 728 | |
| 729 | For exhaustive testing, or testing boring cases that add no value to the |
Fred Drake | 7eb1463 | 2001-02-17 17:32:41 +0000 | [diff] [blame] | 730 | docs, define a \code{__test__} dict instead. That's what it's for. |