From: Fred Drake Date: Mon, 11 Jun 2001 14:57:07 +0000 (+0000) Subject: Merge in recent changes from development branch: add warning about being X-Git-Tag: v2.1.1c1~84 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a623ca8f8032d0b8b1312e5eb0d0c799922f5efd;p=thirdparty%2FPython%2Fcpython.git Merge in recent changes from development branch: add warning about being sure that code only runs once when using the module as both a module and a script. --- diff --git a/Doc/lib/libdoctest.tex b/Doc/lib/libdoctest.tex index 6d19259d257e..9b99b9d51d25 100644 --- a/Doc/lib/libdoctest.tex +++ b/Doc/lib/libdoctest.tex @@ -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}