Rev 6087: (vila) Allow blackbox tests and test scripts interactive debugging. (Vincent in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sat Aug 20 11:49:49 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6087 [merge]
revision-id: pqm at pqm.ubuntu.com-20110820114938-wwxmzhexrielxpq3
parent: pqm at pqm.ubuntu.com-20110820052249-41vfmtn5g0i7ngqb
parent: v.ladeuil+lp at free.fr-20110820074915-kjh3a6re56pvatit
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2011-08-20 11:49:38 +0000
message:
(vila) Allow blackbox tests and test scripts interactive debugging. (Vincent
Ladeuil)
modified:
bzrlib/debug.py debug.py-20061102062349-vdhrw9qdpck8cl35-1
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
doc/developers/HACKING.txt HACKING-20050805200004-2a5dc975d870f78c
doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/debug.py'
--- a/bzrlib/debug.py 2011-08-12 16:25:56 +0000
+++ b/bzrlib/debug.py 2011-08-20 07:49:15 +0000
@@ -24,7 +24,6 @@
for a list of the available options.
"""
-
debug_flags = set()
@@ -36,3 +35,24 @@
c = config.GlobalStack()
for f in c.get('debug_flags'):
debug_flags.add(f)
+
+
+def set_trace():
+ """Pdb using original stdin and stdout.
+
+ When debugging blackbox tests, sys.stdin and sys.stdout are captured for
+ test purposes and cannot be used for interactive debugging. This class uses
+ the origianl stdin/stdout to allow such use.
+
+ Instead of doing:
+
+ import pdb; pdb.set_trace()
+
+ you can do:
+
+ from bzrlib import debug; debug.set_trace()
+ """
+ import pdb
+ import sys
+ pdb.Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__
+ ).set_trace(sys._getframe().f_back)
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2011-08-16 13:12:40 +0000
+++ b/bzrlib/tests/__init__.py 2011-08-19 16:39:25 +0000
@@ -1009,7 +1009,9 @@
def debug(self):
# debug a frame up.
import pdb
- pdb.Pdb().set_trace(sys._getframe().f_back)
+ # The sys preserved stdin/stdout should allow blackbox tests debugging
+ pdb.Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__
+ ).set_trace(sys._getframe().f_back)
def discardDetail(self, name):
"""Extend the addDetail, getDetails api so we can remove a detail.
=== modified file 'doc/developers/HACKING.txt'
--- a/doc/developers/HACKING.txt 2011-06-06 08:24:45 +0000
+++ b/doc/developers/HACKING.txt 2011-08-19 16:55:28 +0000
@@ -436,6 +436,12 @@
be disabled if necessary by setting the environment variable
``BZR_SIGQUIT_PDB=0``.
+All tests inheriting from bzrlib.tests.TestCase can use ``self.debug()``
+instead of the longer ``import pdb; pdb.set_trace()``. The former also works
+when ``stdin/stdout`` are redirected (by using the original ``stdin/stdout``
+file handles at the start of the ``bzr`` script) while the later doesn't.
+``bzrlib.debug.set_trace()`` also uses the original ``stdin/stdout`` file
+handles.
Debug Flags
===========
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-08-20 05:22:49 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-08-20 11:49:38 +0000
@@ -207,6 +207,9 @@
suite. This can include new facilities for writing tests, fixes to
spurious test failures and changes to the way things should be tested.
+* Blackbox tests can be debugged interactively (see bzrlib.debug.BzrPdb for
+ details). (Vincent Ladeuil)
+
* `BranchBuilder.build_snapshot` now supports a "flush" action. This
cleanly and reliably allows tests using `BranchBuilder` to construct
branches that e.g. rename files out of a directory and unversion that
More information about the bazaar-commits
mailing list