pdb + unittest
Peter Hansen
peter at engcorp.com
Tue Apr 13 08:41:55 EDT 2004
Chris Green wrote:
> After forcing myself to start unittest each module I write from the
> get go versus writing some simple apps to excercise some subset of
> functionality, I realized it's pretty hard to use pdb + unittest.
>
> The standard place is a test case is failing, aborting with an assert
> and I want to debug the statement prior to find out what went wrong.
>
> def test_method(self):
> res = self.obj.do_something()
> self.assertEqual(res, 42)
> res = foo(res)
>
>
> Often I want to debug at the first do something so I replace it with:
>
> import pdb
> res = pdb.runcall(self.obj.do_something)
>
> This work great but I don't want pdb to exit from interactive control
> until perhaps after the foo(res) call.
>
> Is there a simple way I could get pdb to shove itself higher up in the
> flow control? How about a mildly complex one? :)
I'm not entirely clear what you're asking, but generally when
I need to use pdb with unit tests (or any other time), I simply
invoke it with "import pdb; pdb.settrace()" and get the prompt
wherever I want it, single step until I'm satisfied, then type
"c" to continue at full speed.
-Peter
More information about the Python-list
mailing list