From 1dc98c44fe31ac7f7256d314e1eaf753b592aca4 Mon Sep 17 00:00:00 2001 From: Skip Montanaro Date: Fri, 8 Jun 2001 14:40:28 +0000 Subject: add warning about situation where code may be executed twice, once when module is __main__ and once when module is imported. --- Doc/lib/libdoctest.tex | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Doc/lib/libdoctest.tex b/Doc/lib/libdoctest.tex index 6d19259..30833da 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} -- cgit v0.12