Module doctest :: Class DocTestCase
[hide private]
[frames] | no frames]

type DocTestCase

       object --+    
                |    
unittest.TestCase --+
                    |
                   DocTestCase
Known Subclasses:

Nested Classes [hide private]

Inherited from unittest.TestCase: failureException

Instance Methods [hide private]
 
__init__(self, test, optionflags=0, setUp=None, tearDown=None, checker=None)
Create an instance of the class that will use the named test method when executed.
 
setUp(self)
Hook method for setting up the test fixture before exercising it.
 
tearDown(self)
Hook method for deconstructing the test fixture after testing it.
 
runTest(self)
 
format_failure(self, err)
 
debug(self)
Run the test case without results and without catching exceptions
 
id(self)
 
__repr__(self)
 
__str__(self)
 
shortDescription(self)
Returns a one-line description of the test, or None if no description has been provided.

Inherited from unittest.TestCase: __call__, assertAlmostEqual, assertAlmostEquals, assertEqual, assertEquals, assertFalse, assertNotAlmostEqual, assertNotAlmostEquals, assertNotEqual, assertNotEquals, assertRaises, assertTrue, assert_, countTestCases, defaultTestResult, fail, failIf, failIfAlmostEqual, failIfEqual, failUnless, failUnlessAlmostEqual, failUnlessEqual, failUnlessRaises, run

Inherited from unittest.TestCase (private): _exc_info

Method Details [hide private]

__init__(self, test, optionflags=0, setUp=None, tearDown=None, checker=None)
(Constructor)

 

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Overrides: unittest.TestCase.__init__
(inherited documentation)

setUp(self)

 

Hook method for setting up the test fixture before exercising it.

Overrides: unittest.TestCase.setUp
(inherited documentation)

tearDown(self)

 

Hook method for deconstructing the test fixture after testing it.

Overrides: unittest.TestCase.tearDown
(inherited documentation)

debug(self)

 

Run the test case without results and without catching exceptions

The unit test framework includes a debug method on test cases and test suites to support post-mortem debugging. The test code is run in such a way that errors are not caught. This way a caller can catch the errors and initiate post-mortem debugging.

The DocTestCase provides a debug method that raises UnexpectedException errors if there is an unexepcted exception:

>>> test = DocTestParser().get_doctest('>>> raise KeyError\n42',
...                {}, 'foo', 'foo.py', 0)
>>> case = DocTestCase(test)
>>> try:
...     case.debug()
... except UnexpectedException, failure:
...     pass

The UnexpectedException contains the test, the example, and the original exception:

>>> failure.test is test
True
>>> failure.example.want
'42\n'
>>> exc_info = failure.exc_info
>>> raise exc_info[0], exc_info[1], exc_info[2]
Traceback (most recent call last):
...
KeyError

If the output doesn't match, then a DocTestFailure is raised:

>>> test = DocTestParser().get_doctest('''
...      >>> x = 1
...      >>> x
...      2
...      ''', {}, 'foo', 'foo.py', 0)
>>> case = DocTestCase(test)
>>> try:
...    case.debug()
... except DocTestFailure, failure:
...    pass

DocTestFailure objects provide access to the test:

>>> failure.test is test
True

As well as to the example:

>>> failure.example.want
'2\n'

and the actual output:

>>> failure.got
'1\n'
Overrides: unittest.TestCase.debug

id(self)

 
Overrides: unittest.TestCase.id

__repr__(self)
(Representation operator)

 
Overrides: unittest.TestCase.__repr__

__str__(self)
(Informal representation operator)

 
Overrides: unittest.TestCase.__str__

shortDescription(self)

 

Returns a one-line description of the test, or None if no description has been provided.

The default implementation of this method returns the first line of the specified test method's docstring.

Overrides: unittest.TestCase.shortDescription
(inherited documentation)