Package zope :: Package testing :: Module doctest :: Class DebugRunner
[show private | hide private]
[frames | no frames]

Class DebugRunner

DocTestRunner --+
                |
               DebugRunner


Run doc tests but raise an exception as soon as there is a failure.

If an unexpected exception occurs, an UnexpectedException is raised. It contains the test, the example, and the original exception:

>>> runner = DebugRunner(verbose=False)
>>> test = DocTestParser().get_doctest('>>> raise KeyError\n42',
...                                    {}, 'foo', 'foo.py', 0)
>>> try:
...     runner.run(test)
... except UnexpectedException, failure:
...     pass
>>> 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

We wrap the original exception to give the calling application access to the test and example information.

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

>>> test = DocTestParser().get_doctest('''
...      >>> x = 1
...      >>> x
...      2
...      ''', {}, 'foo', 'foo.py', 0)
>>> try:
...    runner.run(test)
... 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'

If a failure or error occurs, the globals are left intact:

>>> del test.globs['__builtins__']
>>> test.globs
{'x': 1}
>>> test = DocTestParser().get_doctest('''
...      >>> x = 2
...      >>> raise KeyError
...      ''', {}, 'foo', 'foo.py', 0)
>>> runner.run(test)
Traceback (most recent call last):
...
UnexpectedException: <DocTest foo from foo.py:0 (2 examples)>
>>> del test.globs['__builtins__']
>>> test.globs
{'x': 2}

But the globals are cleared if there is no error:

>>> test = DocTestParser().get_doctest('''
...      >>> x = 2
...      ''', {}, 'foo', 'foo.py', 0)
>>> runner.run(test)
(0, 1)
>>> test.globs
{}

Method Summary
  report_failure(self, out, test, example, got)
Report that the given example failed.
  report_unexpected_exception(self, out, test, example, exc_info)
Report that the given example raised an unexpected exception.
  run(self, test, compileflags, out, clear_globs)
Run the examples in test, and display the results using the writer function out.
    Inherited from DocTestRunner
  __init__(self, checker, verbose, optionflags)
Create a new test runner.
  merge(self, other)
  report_start(self, out, test, example)
Report that the test runner is about to process the given example.
  report_success(self, out, test, example, got)
Report that the given example ran successfully.
  summarize(self, verbose)
Print a summary of all the test cases that have been run by this DocTestRunner, and return a tuple (f, t), where f is the total number of failed examples, and t is the total number of tried examples.

Class Variable Summary
    Inherited from DocTestRunner
str DIVIDER = '*********************************************...

Method Details

report_failure(self, out, test, example, got)

Report that the given example failed.

Overrides:
zope.testing.doctest.DocTestRunner.report_failure (inherited documentation)

report_unexpected_exception(self, out, test, example, exc_info)

Report that the given example raised an unexpected exception.

Overrides:
zope.testing.doctest.DocTestRunner.report_unexpected_exception (inherited documentation)

run(self, test, compileflags=None, out=None, clear_globs=True)

Run the examples in test, and display the results using the writer function out.

The examples are run in the namespace test.globs. If clear_globs is true (the default), then this namespace will be cleared after the test runs, to help with garbage collection. If you would like to examine the namespace after the test completes, then use clear_globs=False.

compileflags gives the set of flags that should be used by the Python compiler when running the examples. If not specified, then it will default to the set of future-import flags that apply to globs.

The output of each example is checked using DocTestRunner.check_output, and the results are formatted by the DocTestRunner.report_* methods.

Overrides:
zope.testing.doctest.DocTestRunner.run (inherited documentation)

Generated by Epydoc 2.1 on Fri Jun 24 12:01:26 2005 http://epydoc.sf.net