]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merge in recent changes from development branch: add warning about being
authorFred Drake <fdrake@acm.org>
Mon, 11 Jun 2001 14:57:07 +0000 (14:57 +0000)
committerFred Drake <fdrake@acm.org>
Mon, 11 Jun 2001 14:57:07 +0000 (14:57 +0000)
sure that code only runs once when using the module as both a module and a
script.

Doc/lib/libdoctest.tex

index 6d19259d257eafc0f8dbb5509b74a0712277be17..9b99b9d51d25f888c51b958dbb96d2d1c3d4f6e6 100644 (file)
@@ -406,6 +406,17 @@ often contrive doctest examples to produce numbers of that form:
 
 Simple fractions are also easier for people to understand, and that makes
 for better documentation.
+
+\item Be careful if you have code that must only execute once.
+
+If you have module-level code that must only execute once, a more foolproof
+definition of \function{_test()} is
+
+\begin{verbatim}
+def _test():
+    import doctest, sys
+    doctest.testmod(sys.modules["__main__"])
+\end{verbatim}
 \end{enumerate}