Robotframework (http://code.google.com/p/robotframework/) is a tool used to run functional tests against a variety of targets. Tests are organized in the form of keyword tsv or html files, which map input parameters to keyword-argument methods in the test suite. Robot includes a fairly advanced logging mechanism, which is cool -- until you try to debug anything. Debugging is made difficult because robot steals stdin and stdout when it is run, which means bye-bye debugging in the terminal. rpdb solves this in a KISS simple way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import pdb IO = lambda s: (s.stdin, s.stdout) def rpdb(F): """ robot python debugger -- usage: @rpdb def keyword_method(self, arg1, arg2, ...): # stuff here ... rpdb.set_trace() # set breakpoint as usual # more code ... """ setattr(rpdb, 'set_trace', pdb.set_trace) builtinIO = IO(sys) def _inner(*args, **kwargs): robotIO = IO(sys) # robot has hijacked stdin/stdout pdb.sys.stdin, pdb.sys.stdout = builtinIO retval = F(*args, **kwargs) sys.stdin, sys.stdout = robotIO return retval return _inner
The recipe is pretty self explanatory. Before robot's __init__ can be called the decorators must wrap the kwarg methods. Since stdin/stdout have not been stolen yet, we save them to a variable inside the decorator's scope. This forms a closure; and right before calling the method we intend to debug, rpdb switches out stdin/stdout temporarily returning control to the terminal. Once debugging is completed, stdin/stdout are returned to robot. Happy debugging all.