pdb + unittest

C

Chris Green

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? :)

Thanks,
Chris
 
P

Peter Hansen

Chris said:
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
 
C

Chris Green

Peter Hansen said:
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.

Thanks! For some reason, I thought you had to pass set_trace an
argument of the frame you wanted. That's exactly what I want :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top