14

For learning purposes I want to follow the execution path in a robot framework python library. Actually the ssh library

What is the best way to do this?

I have looked at debug lib , which seems to provide me with the ability to set a breakpoint and spawn a new shell. However I want to examine the execution flow, the stack and the variable values set. Something like pudb but triggered via pybot. Is this possible?

Dave
  • 4,184
  • 8
  • 40
  • 46

3 Answers3

24

You can use pdb with robot. How to do so is documented in the robot framework user guide, in the section titled Using the python debugger (pdb).

The example it gives is to add this where you want to set a breakpoint:

import sys, pdb; pdb.Pdb(stdout=sys.__stdout__).set_trace()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • That did it, I opened lib/python2.7/site-packages/SSHLibrary/library.py and added import sys, pdb; pdb.Pdb(stdout=sys.__stdout__).set_trace() to a keyword function. – Dave Oct 06 '15 at 22:20
3

As I prefer to use ipdb more than pdb, then here is my way to use it with robot

import ipdb; ipdb.stdout.update_stdout(); ipdb.stdout.set_trace()

Hint: For some reason the autocomplete wont be working using pdb nor ipdb so if u care about the autocomplete u need to install pdbpp via pip install pdbpp then add this to your code

import sys
import pdb
for attr in ('stdin', 'stdout', 'stderr'):
    setattr(sys, attr, getattr(sys, '__%s__' % attr))
pdb.set_trace()
IslamTaha
  • 1,056
  • 1
  • 10
  • 17
  • Better: `export PYTHONBREAKPOINT=ipdb.sset_trace` then in your Python sources you use `breakpoint()`. `sset_trace` is basically an ipdb-provided alias for `ipdb.stdout.update_stdout(); ipdb.stdout.set_trace()` – Apteryx Apr 25 '22 at 15:04
0

You can debug directly in robot files, without creating a keyword:

Evaluate    pdb.Pdb(stdout=sys.__stdout__).set_trace()    modules=sys, pdb

https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#using-the-python-debugger-pdb

Ramon Medeiros
  • 2,272
  • 2
  • 24
  • 41