From a623ca8f8032d0b8b1312e5eb0d0c799922f5efd Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Mon, 11 Jun 2001 14:57:07 +0000 Subject: [PATCH] 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. --- Doc/lib/libdoctest.tex | 11 +++++++++++ 1 file changed, 11 insertions(+) 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} -- 2.47.3