Index: pdb.py =================================================================== --- pdb.py (revision 80143) +++ pdb.py (working copy) @@ -61,7 +61,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None): bdb.Bdb.__init__(self, skip=skip) cmd.Cmd.__init__(self, completekey, stdin, stdout) - if stdout: + if stdout and stdout != sys.stdout: self.use_rawinput = 0 self.prompt = '(Pdb) ' self.aliases = {} Index: doctest.py =================================================================== --- doctest.py (revision 80143) +++ doctest.py (working copy) @@ -1361,7 +1361,6 @@ save_stdout = sys.stdout if out is None: out = save_stdout.write - sys.stdout = self._fakeout # Patch pdb.set_trace to restore sys.stdout during interactive # debugging (so it's not still redirected to self._fakeout). @@ -1373,6 +1372,8 @@ self.debugger.reset() pdb.set_trace = self.debugger.set_trace + sys.stdout = self._fakeout + # Patch linecache.getlines, so we can see the example's source # when we're inside the debugger. self.save_linecache_getlines = linecache.getlines Index: test/test_doctest.py =================================================================== --- test/test_doctest.py (revision 80537) +++ test/test_doctest.py (working copy) @@ -1583,6 +1583,17 @@ """ +def test_pdb_readline_use (): + """ + When using pdb in doctest's test cases, the readline library + must be used to retrieve pdb commands from history + + Readline method is enabled when Cmd's use_rawinput varaible is 1. + + >>> doctest_pdb = doctest._OutputRedirectingPdb (sys.stdout) + >>> assert doctest_pdb.use_rawinput == 1, 'Readline not used' + """ + def test_pdb_set_trace(): """Using pdb.set_trace from a doctest. @@ -1592,7 +1603,7 @@ capture program output. It also temporarily replaces pdb.set_trace with a version that restores stdout. This is necessary for you to see debugger output. - + >>> doc = ''' ... >>> x = 42 ... >>> import pdb; pdb.set_trace()