1
##############################################################################
3
# Copyright (c) 2004-2008 Zope Foundation and Contributors.
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
13
##############################################################################
16
$Id: __init__.py 86232 2008-05-03 15:09:33Z ctheune $
24
import zope.testing.testrunner.interfaces
27
def post_mortem(exc_info):
29
if isinstance(err, (doctest.UnexpectedException, doctest.DocTestFailure)):
31
if isinstance(err, doctest.UnexpectedException):
32
exc_info = err.exc_info
34
# Print out location info if the error was in a doctest
35
if exc_info[2].tb_frame.f_code.co_filename == '<string>':
36
print_doctest_location(err)
39
print_doctest_location(err)
40
# Hm, we have a DocTestFailure exception. We need to
41
# generate our own traceback
43
exec ('raise ValueError'
44
'("Expected and actual output are different")'
47
exc_info = sys.exc_info()
49
print "%s:" % (exc_info[0], )
51
pdb.post_mortem(exc_info[2])
52
raise zope.testing.testrunner.interfaces.EndRun()
55
def print_doctest_location(err):
56
# This mimics pdb's output, which gives way cool results in emacs :)
57
filename = err.test.filename
58
if filename.endswith('.pyc'):
59
filename = filename[:-1]
60
print "> %s(%s)_()" % (filename, err.test.lineno+err.example.lineno+1)