[New-bugs-announce] [issue4938] Pdb cannot access doctest source in postmortem

Alexander Belopolsky report at bugs.python.org
Tue Jan 13 23:55:44 CET 2009


New submission from Alexander Belopolsky <belopolsky at users.sourceforge.net>:

With attached x.py:

$ cat x.py
"""
>>> foo()
"""
def foo():
    1/0

if __name__ == '__main__':
    import doctest, pdb
    try:
        doctest.testmod(raise_on_error=True)
    except doctest.UnexpectedException, e:
        pdb.post_mortem(e.exc_info[2])

$ ./python.exe x.py
> /Users/sasha/Work/python-svn/trunk/x.py(5)foo()
-> 1/0
(Pdb) up
> <doctest __main__[0]>(1)<module>()
(Pdb) l
[EOF]


Apparently the problem is that the default getlines gets restored in the  
"finally:" section in DocTestRunner.run() before post_mortem is invoked.

The only solution that comes to mind is to patch pdb.post_mortem 
similarly to the way pdb.set_trace is patched but not restore it until 
the end of testmod().

Am I missing a simpler solution?

----------
files: x.py
messages: 79787
nosy: belopolsky
severity: normal
status: open
title: Pdb cannot access doctest source in postmortem
Added file: http://bugs.python.org/file12727/x.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4938>
_______________________________________


More information about the New-bugs-announce mailing list