views:

26

answers:

1

Is it possible to set breakpoints in doctests, using PyDev (i.e. eclipse)? I found that while I am seemingly able to do so, the breakpoints do not work at all.

To have some code in the question, and to clarify, say I have

def funct():
  """
  >>> funct()
  Whatever
  """
  print "Whatever"

and that I set a breakpoint at the funct() call in the doctest. Can I do that?

PS: I know I can do

import pdb; pdb.set_trace()

to have a prompt in a doctest, but I would prefer not inserting such lines.

A: 

I don't think you can set breakpoints in strings.

doctest is a module for automated testing. If you need to debug your doctest code, why not run it normally and verify the output, then once you know it works, throw it into a docstring?

Alex Bliskovsky
I find it easier to write doctests a la pre- and postconditions as one of the first things to do when implementing a method. One of the things I like the most about docstests is that I generally do not have to do that copy-paste routine and use my "tinker'n'test" code as the test code with no additional effort. I was looking to fulfilling my fantasy by using pydev breakpoints but it seems I'm stuck with set_trace(). I find my especially in need of such breakpoints when I break my code i.e. when doctests start to fail after a change. I can copy-and-paste or throw in a set_trace(), but still.
Kerem