[Python-checkins] python/dist/src/Doc/lib libdoctest.tex,1.53,1.54

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Sun Sep 26 04:12:42 CEST 2004


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30898/Doc/lib

Modified Files:
	libdoctest.tex 
Log Message:
Document set_unittest_reportflags().


Index: libdoctest.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libdoctest.tex,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- libdoctest.tex	25 Sep 2004 08:09:23 -0000	1.53
+++ libdoctest.tex	26 Sep 2004 02:12:40 -0000	1.54
@@ -933,8 +933,8 @@
 way to combine doctests from multiple modules. \class{Tester} was feeble,
 and in practice most serious Python testing frameworks build on the
 \module{unittest} module, which supplies many flexible ways to combine
-tests from multiple sources.  So, in Python 2.4, module{doctest}'s
-\class{Tester} class is deprecated, and \module{doctest} provides several
+tests from multiple sources.  So, in Python 2.4, \module{doctest}'s
+\class{Tester} class is deprecated, and \module{doctest} provides two
 functions that can be used to create \module{unittest} test suites from
 modules and text files containing doctests.  These test suites can then be
 run using \module{unittest} test runners:
@@ -951,6 +951,9 @@
 runner.run(suite)
 \end{verbatim}
 
+There are two main functions for creating \class{unittest.TestSuite}
+instances from text files and modules with doctests:
+
 \begin{funcdesc}{DocFileSuite}{*paths, **kw}
   Convert doctest tests from one or more text files to a
   \class{\refmodule{unittest}.TestSuite}.
@@ -1011,6 +1014,8 @@
   Optional argument \var{optionflags} specifies the default
   doctest options for the tests, created by or-ing together
   individual option flags.  See section~\ref{doctest-options}.
+  See function \function{set_unittest_reportflags()} below for
+  a better way to set reporting options.
 
   \versionadded{2.4}
 \end{funcdesc}
@@ -1049,12 +1054,64 @@
   are the same as for function \function{DocFileSuite()} above.
 
   \versionadded{2.3}
+
   \versionchanged[The parameters \var{globs}, \var{extraglobs},
     \var{test_finder}, \var{setUp}, \var{tearDown}, and
     \var{optionflags} were added; this function now uses the same search
     technique as \function{testmod()}]{2.4}
 \end{funcdesc}
 
+Under the covers, \function{DocTestSuite()} creates a
+\class{unittest.TestSuite} out of \class{doctest.DocTestCase} instances,
+and \class{DocTestCase} is a subclass of \class{unittest.TestCase}.
+\class{DocTestCase} isn't documented here (it's an internal detail), but
+studying its code can answer questions about the exact details of
+\module{unittest} integration.
+
+Similarly, \function{DocFileSuite()} creates a \class{unittest.TestSuite}
+out of \class{doctest.DocFileCase} instances, and \class{DocFileCase}
+is a subclass of \class{DocTestCase}.
+
+So both ways of creating a \class{unittest.TestSuite} run instances of
+\class{DocTestCase}.  This is important for a subtle reason:  when you
+run \module{doctest} functions yourself, you can control the
+\module{doctest} options in use directly, by passing option flags to
+\module{doctest} functions.  However, if you're writing a \module{unittest}
+framework, \module{unittest} ultimately controls when and how tests
+get run.  The framework author typically wants to control \module{doctest}
+reporting options (perhaps, e.g., specified by command line options),
+but there's no way to pass options through \module{unittest} to
+\module{doctest} test runners.
+
+For this reason, \module{doctest} also supports a notion of
+\module{doctest} reporting flags specific to \module{unittest} support,
+via this function:
+
+\begin{funcdesc}{set_unittest_reportflags}{flags}
+  Set the \module{doctest} reporting flags to use.
+
+  Argument \var{flags} or's together option flags.  See
+  section~\ref{doctest-options}.  Only "reporting flags" can be used.
+
+  This is a module-global setting, and affects all future doctests run
+  by module \module{unittest}:  the \method{runTest()} method of
+  \class{DocTestCase} looks at the option flags specified for the test
+  case when the \class{DocTestCase} instance was constructed.  If no
+  reporting flags were specified (which is the typical and expected case),
+  \module{doctest}'s \module{unittest} reporting flags are or'ed into the
+  option flags, and the option flags so augmented are passed to the
+  \class{DocTestRunner} instance created to run the doctest.  If any
+  reporting flags were specified when the \class{DocTestCase} instance
+  was constructed, \module{doctest}'s \module{unittest} reporting flags
+  are ignored.
+
+  The value of the \module{unittest} reporting flags in effect before the
+  function was called is returned by the function.
+
+  \versionadded{2.4}
+\end{funcdesc}
+
+
 \subsection{Advanced API\label{doctest-advanced-api}}
 
 The basic API is a simple wrapper that's intended to make doctest easy



More information about the Python-checkins mailing list