Skip to content

Instantly share code, notes, and snippets.

@bbbco
Created November 20, 2013 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbbco/7567794 to your computer and use it in GitHub Desktop.
Save bbbco/7567794 to your computer and use it in GitHub Desktop.
Robot Framework Python Debugger based on Daniel Cohn's recipe at http://code.activestate.com/recipes/578073-rpdb-robotpythondebugger-a-smarter-way-to-debug-ro/ fixed and updated for Python 2.7 / Robot Framework 2.8.x by Brian Goad. Allows you to jump into the code and debug your custom Python keywords. Wraps pdb because Robot Framework steals th…
import pdb
import sys
IO = lambda s: (s.__stdin__, s.__stdout__)
def rpdb(F):
"""
Robot Framework Python Debugger based on Daniel Cohn's recipe at
http://code.activestate.com/recipes/578073-rpdb-robotpythondebugger-a-smarter-way-to-debug-ro/
fixed and updated for Python 2.7 / Robot Framework 2.8.x by Brian Goad.
--
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
@bbbco
Copy link
Author

bbbco commented Nov 20, 2013

FWIW, I had to fix the original code by using sys.stdin and sys.stdout ... was clued into this from http://bugs.python.org/issue6333

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment