This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Pdb cannot access doctest source in postmortem
Type: behavior Stage: needs patch
Components: Versions: Python 3.2
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: belopolsky Nosy List: belopolsky, georg.brandl, jonathan.cervidae
Priority: normal Keywords:

Created on 2009-01-13 22:55 by belopolsky, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
x.py belopolsky, 2009-01-13 22:55
Messages (4)
msg79787 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2009-01-13 22:55
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?
msg87500 - (view) Author: Jonathan (jonathan.cervidae) Date: 2009-05-09 14:58
#!/usr/bin/env python
# This does what you want. Change pydb for pdb if you prefer it.
import pydb
import doctest
import sys
sys.excepthook = pydb.exception_hook
try:
    doctest.testfile("story.txt",verbose=False,raise_on_error=True)
except doctest.UnexpectedException, failure:
    pass
exc_info = failure.exc_info
raise exc_info[0], exc_info[1], exc_info[2]
msg87501 - (view) Author: Jonathan (jonathan.cervidae) Date: 2009-05-09 15:11
#!/usr/bin/env python
# Slight mistake in last post
import pydb
import doctest
import sys
sys.excepthook = pydb.exception_hook
try:
    doctest.testfile("story.txt",verbose=False,raise_on_error=True)
except doctest.UnexpectedException, failure:
    exc_info = failure.exc_info
    raise exc_info[0], exc_info[1], exc_info[2]
msg112056 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-30 09:30
I think this is just too complicated to implement in a sane way.  doctest+pdb is just a bit too hacky to be fully supported.
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49188
2010-07-30 09:30:36georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112056

resolution: wont fix
2010-07-18 18:02:43belopolskysetassignee: belopolsky
stage: needs patch
type: behavior
versions: + Python 3.2
2009-05-09 15:11:39jonathan.cervidaesetmessages: + msg87501
2009-05-09 14:58:17jonathan.cervidaesetnosy: + jonathan.cervidae
messages: + msg87500
2009-01-13 22:55:43belopolskycreate