[Python-checkins] python/dist/src/Doc/lib libunittest.tex,1.7,1.8

fdrake@users.sourceforge.net fdrake@users.sourceforge.net
Tue, 02 Jul 2002 15:34:47 -0700


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory usw-pr-cvs1:/tmp/cvs-serv23159/lib

Modified Files:
	libunittest.tex 
Log Message:
Update the documentation of the errors and failures attributes of the
TestResult object.  Add an example of how to get even more information for
apps that can use it.
Closes SF bug #558278.


Index: libunittest.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libunittest.tex,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** libunittest.tex	20 Oct 2001 04:24:09 -0000	1.7
--- libunittest.tex	2 Jul 2002 22:34:44 -0000	1.8
***************
*** 610,615 ****
  failures and errors that occurred among those test runs.  The
  collections contain tuples of \code{(\var{testcase},
! \var{exceptioninfo})}, where \var{exceptioninfo} is a tuple as
! returned by \function{sys.exc_info()}.
  
  \class{TestResult} instances have the following attributes that will
--- 610,615 ----
  failures and errors that occurred among those test runs.  The
  collections contain tuples of \code{(\var{testcase},
! \var{traceback})}, where \var{traceback} is a string containing a
! formatted version of the traceback for the exception.
  
  \class{TestResult} instances have the following attributes that will
***************
*** 618,629 ****
  \begin{memberdesc}[TestResult]{errors}
    A list containing pairs of \class{TestCase} instances and the
!   \function{sys.exc_info()} results for tests which raised an
!   exception but did not signal a test failure.
  \end{memberdesc}
  
  \begin{memberdesc}[TestResult]{failures}
    A list containing pairs of \class{TestCase} instances and the
!   \function{sys.exc_info()} results for tests which signalled a
!   failure in the code under test.
  \end{memberdesc}
  
--- 618,629 ----
  \begin{memberdesc}[TestResult]{errors}
    A list containing pairs of \class{TestCase} instances and the
!   formatted tracebacks for tests which raised an exception but did not
!   signal a test failure.
  \end{memberdesc}
  
  \begin{memberdesc}[TestResult]{failures}
    A list containing pairs of \class{TestCase} instances and the
!   formatted tracebacks for tests which signalled a failure in the code
!   under test.
  \end{memberdesc}
  
***************
*** 770,771 ****
--- 770,813 ----
    the \class{TestSuite} class.
  \end{memberdesc}
+ 
+ 
+ \subsection{Getting Extended Error Information
+             \label{unittest-error-info}}
+ 
+ Some applications can make use of more error information (for example,
+ an integrated development environment, or IDE).  Such an application
+ can retrieve supplemental information about errors and failures by
+ using an alternate \class{TestResult} implementation, and extending
+ the \method{defaultTestResult()} method of the \class{TestCase} class
+ to provide it.
+ 
+ Here is a brief example of a \class{TestResult} subclass which stores
+ the actual exception and traceback objects.  (Be aware that storing
+ traceback objects can cause a great deal of memory not to be reclaimed
+ when it otherwise would be, which can have effects that affect the
+ behavior of the tests.)
+ 
+ \begin{verbatim}
+ import unittest
+ 
+ class MyTestCase(unittest.TestCase):
+     def defaultTestResult(self):
+         return MyTestResult()
+ 
+ class MyTestResult(unittest.TestResult):
+     def __init__(self):
+         self.errors_tb = []
+         self.failures_tb = []
+ 
+     def addError(self, test, err):
+         self.errors_tb.append((test, err))
+         unittest.TestResult.addError(self, test, err)
+ 
+     def addFailure(self, test, err):
+         self.failures_tb.append((test, err))
+         unittest.TestResult.addFailure(self, test, err)
+ \end{verbatim}
+ 
+ Tests written using \class{MyTestCase} as the base class, instead of
+ \class{TestCase}, will allow tools to extract additional information
+ from the results object.