Index: pdb.py =================================================================== --- pdb.py (revision 80760) +++ 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 is not None and stdout is not sys.stdout: self.use_rawinput = 0 self.prompt = '(Pdb) ' self.aliases = {} Index: doctest.py =================================================================== --- doctest.py (revision 80760) +++ 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_pdb.py =================================================================== --- test/test_pdb.py (revision 80760) +++ test/test_pdb.py (working copy) @@ -3,6 +3,7 @@ import imp import sys +import unittest from test import test_support # This little helper class is essential for testing pdb under doctest. @@ -126,10 +127,36 @@ """ +import pdb +class TestPdbReadline (unittest.TestCase): + + def setUp (self): + self.iscalled = False + def fake_rawinput (prompt): + self.iscalled = True + return self.real_rawinput (prompt) + self.real_rawinput = __builtins__.raw_input + self.real_stdin = sys.stdin + sys.stdin = _FakeInput (["continue"]) + __builtins__.raw_input = fake_rawinput + self.pdb_inst = pdb.Pdb (stdout = sys.stdout, stdin = sys.stdin) + self.pdb_inst.set_trace (sys._getframe()) + + def testreadline (self): + self.assertEqual(self.iscalled, True) + + def tearDown (self): + __builtins__.raw_input = self.real_rawinput + sys.stdin = self.real_stdin + + + + def test_main(): from test import test_pdb test_support.run_doctest(test_pdb, verbosity=True) + suite = unittest.TestLoader().loadTestsFromTestCase(TestPdbReadline) + unittest.TextTestRunner(verbosity=1).run(suite) - if __name__ == '__main__': test_main()