4

I have a unittest that throws an exception. The exception isn't thrown by my code, it's from somewhere deep within django. I want to open a pdb session at that spot and see what's the haps, but when I open ipython with pdb and run test myapp the test runs, throws the exception, prints it, but pdb doesn't catch anything.

I guess the desperate-man's solution is to open up django's source and insert import pdb; pdb.set_trace() at the spot I want to investigate. But there's gotta be a better way. What am I missing?

pseudosudo
  • 6,270
  • 9
  • 40
  • 53

2 Answers2

2

perhaps using nosetests to run your tests with the --pdb option would work.

shaunc
  • 5,317
  • 4
  • 43
  • 58
0

Why don't you put a breakpoint ( import pdb; pdb.set_trace() ) at your code and inspect the process? I mean, with the letter 's' you can enter inside a function, so you can go deep until the Django code.

I don't know why you think that using the breakpoint as you say is a bad solution. Actually, that's how I debug all my code.

BTW: Try ipdb insteand pdb. You will love it ;)

pyriku
  • 1,251
  • 7
  • 17
  • -1 Test runners should provide a post-mortem debugger (i.e., it calls set_trace where an error occurs) so users don't need to do this manually deep inside the interals of massive packages like django – twneale Apr 03 '14 at 20:13