views:

37

answers:

1

How can I break into a running test with the pdb interactive debugger?

This is the test:

class UserTestCase(TestCase):
  def test_register_should_create_UserProfile(self):
    c = Client()
    response = c.post('/account/register/', {u'username': [u'john'], u'email': [u'[email protected]'], u'bnewaccount': [u'Signup']})

    self.assertEqual(response.status_code, 302)
    import pdb; pdb.set_trace()
    user = User.objects.get( username ='john')
    self.assertTrue(user.get_profile())

When I attempt to run the tests:
$ python manage.py test

The test database is created. The progress dots '.' begin to progress across the screen as the tests pass. Then the progess stops.

I am never shown a pdb> prompt in the terminal window.

How can I get pdb to work properly?

+1  A: 

Have you tried ipdb instead of vanilla pdb? I use ipdb and what you're trying to do works fine.

Alternatively, as a fallback, why not try the pdb call inside the method you're testing, just before the response is returned?

stevejalim
iPdb does work. I'll just use that as my default debugger.
BryanWheelock
There should be zero difference between ipdb and pdb in the example usage. They should both work just fine. I would have started by moving the import to the first line of the test instead of by switching tools. Switching tools may be masking a different problem.
istruble