From: Skip Montanaro Date: Fri, 8 Jun 2001 14:40:28 +0000 (+0000) Subject: add warning about situation where code may be executed twice, once when X-Git-Tag: v2.2a3~1595 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1dc98c44fe31ac7f7256d314e1eaf753b592aca4;p=thirdparty%2FPython%2Fcpython.git add warning about situation where code may be executed twice, once when module is __main__ and once when module is imported. --- diff --git a/Doc/lib/libdoctest.tex b/Doc/lib/libdoctest.tex index 6d19259d257e..30833da181a1 100644 --- a/Doc/lib/libdoctest.tex +++ b/Doc/lib/libdoctest.tex @@ -408,6 +408,16 @@ Simple fractions are also easier for people to understand, and that makes for better documentation. \end{enumerate} +\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} \subsection{Soapbox}