classification
Title: doctest pdb readline broken
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.1, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: sriram, wosc (2)
Priority: Keywords patch

Created on 2009-04-09 11:25 by wosc, last changed 2009-09-19 21:13 by sriram.

Files
File name Uploaded Description Edit Remove
doctest-readline.patch wosc, 2009-06-05 14:59
Messages (3)
msg85808 - (view) Author: Wolfgang Schnerring (wosc) Date: 2009-04-09 11:25
When pdb is called from inside a doctest under python2.5, the readline
keys do not work anymore -- like they did just fine in 2.4.

Steps to reproduce: 
1. Create two files, foo.txt and foo.py, like so:
$ cat > foo.txt
>>> import pdb; pdb.set_trace()
$ cat > foo.py
import doctest; doctest.testfile('foo.txt')
2. run it
$ python2.5 foo.py
3. If I now press Ctrl-P, I get "^P" printed on the prompt, instead of
going back in the readline history. Likewise, the arrow keys print
escape sequences instead of moving the cursor.
msg88948 - (view) Author: Wolfgang Schnerring (wosc) Date: 2009-06-05 14:59
I've tracked down the reason by diffing pdb.py and cmd.py between 2.4
and 2.5:
It turns out that pdb.Pdb in 2.5 changes the way it handles input
depending on whether an explicit output was provided, more precisely, it
disables readline in that case. I don't understand what's going on here,
but there is a simple, non-intrusive fix on the doctest side, see the
attached patch.

Unfortunately, I can't imagine how to write a test to check this behaviour.
msg92878 - (view) Author: Sriram (sriram) Date: 2009-09-19 21:13
Hi,

How about changing pdb's behavior, that it disables readline only if the 
passed stream is not the stdout stream?

Also when looking at doctest module, I found that bdb's trace_dispatch 
was overridden to set the debugger's output stream to something other 
than stdout. I presume, that since prior to 2.5, pdb never took the 
stdin and stdout arguments and that overridden method was needed to make 
pdb use a stream other than stdout, but now that 2.5 allows us to pass 
the output stream in init method of pdb, that function is no longer 
needed.

Thanks
History
Date User Action Args
2009-09-19 21:13:27sriramsetnosy: + sriram
messages: + msg92878
2009-06-05 14:59:08woscsetfiles: + doctest-readline.patch
keywords: + patch
messages: + msg88948
2009-04-22 04:12:48ajaksu2setstage: test needed
versions: + Python 2.6, Python 3.1, - Python 2.5
2009-04-09 11:25:03wosccreate