summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-06-11 14:57:07 (GMT)
committerFred Drake <fdrake@acm.org>2001-06-11 14:57:07 (GMT)
commita623ca8f8032d0b8b1312e5eb0d0c799922f5efd (patch)
tree0136cfc568653acbc38e6016104446e7290e0e1c
parentceea6feb35751c9e4e36f4689affa9465d249f23 (diff)
downloadcpython-a623ca8f8032d0b8b1312e5eb0d0c799922f5efd.zip
cpython-a623ca8f8032d0b8b1312e5eb0d0c799922f5efd.tar.gz
cpython-a623ca8f8032d0b8b1312e5eb0d0c799922f5efd.tar.bz2
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.
-rw-r--r--Doc/lib/libdoctest.tex11
1 files changed, 11 insertions, 0 deletions
diff --git a/Doc/lib/libdoctest.tex b/Doc/lib/libdoctest.tex
index 6d19259..9b99b9d 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}