]> granicus.if.org Git - python/commitdiff
Patch #486438: Make module argument to testmod optional.
authorMartin v. Löwis <martin@v.loewis.de>
Fri, 22 Nov 2002 08:23:09 +0000 (08:23 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Fri, 22 Nov 2002 08:23:09 +0000 (08:23 +0000)
Doc/lib/libdoctest.tex
Lib/doctest.py
Misc/NEWS

index edd78a410c46369f1822213418a7ea0a569dd437..9a795e949b36b58340eb7639fe4361c1103adbcb 100644 (file)
@@ -152,6 +152,10 @@ if __name__ == "__main__":
     _test()
 \end{verbatim}
 
+If you want to test the module as the main module, you don't need to
+pass M to \function{testmod}; in this case, it will test the current
+module.
+
 Then running the module as a script causes the examples in the docstrings
 to get executed and verified:
 
@@ -392,7 +396,7 @@ definition of \function{_test()} is
 \begin{verbatim}
 def _test():
     import doctest, sys
-    doctest.testmod(sys.modules["__main__"])
+    doctest.testmod()
 \end{verbatim}
 \end{enumerate}
 
index 5cbdd06a9e2bd5feca3d6cb178466e4f610da7dc..c01606dca6ae739533fe4472ac3c21f885d8ff47 100644 (file)
@@ -1044,12 +1044,13 @@ see its docs for details.
 
 master = None
 
-def testmod(m, name=None, globs=None, verbose=None, isprivate=None,
+def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None,
                report=1):
-    """m, name=None, globs=None, verbose=None, isprivate=None, report=1
+    """m=None, name=None, globs=None, verbose=None, isprivate=None, report=1
 
-    Test examples in docstrings in functions and classes reachable from
-    module m, starting with m.__doc__.  Private names are skipped.
+    Test examples in docstrings in functions and classes reachable
+    from module m (or the current module if m is not supplied), starting
+    with m.__doc__.  Private names are skipped.
 
     Also test examples reachable from dict m.__test__ if it exists and is
     not None.  m.__dict__ maps names to functions, classes and strings;
@@ -1090,6 +1091,13 @@ def testmod(m, name=None, globs=None, verbose=None, isprivate=None,
 
     global master
 
+    if m is None:
+        import sys
+        # DWA - m will still be None if this wasn't invoked from the command
+        # line, in which case the following TypeError is about as good an error
+        # as we should expect
+        m = sys.modules.get('__main__')
+
     if not _ismodule(m):
         raise TypeError("testmod: module required; " + `m`)
     if name is None:
index 42cd9183365c07eb12736e3d130488dcc72e6185..d29cccb01cc67a3b8f213d1120bfa8c2b5b5354a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -389,6 +389,9 @@ Extension modules
 Library
 -------
 
+- doctest.testmod can now be called without argument, which means to
+  test the current module.
+
 - When cancelling a server that implemented threading with a keyboard
   interrupt, the server would shut down but not terminate (waiting on
   client threads). A new member variable, daemon_threads, was added to