Debugging custom Robot Framework libraries

I'm a huge fan of Robot Framework and I've been developing custom libraries for a while now. I'm slightly embarassed to admit that my primary method of debugging has been with robot.api.logger statements sprinkled into problematic code. But I've recently found two significantly better ways to shake out bugs, with VS Code and pdb.

VS Code

I started using VS Code's debugger first. The only extra step involved is to create a python script that will run the test. Here's an example script:

from pathlib import Path

import robot

if __name__ == "__main__":
    robot_test = Path("/path/to/test_cases/test.robot")
    robot.run(str(robot_test))

Simply open this up in VS Code, set breakpoints, and run. See the Debugging in VS Code documentation for all of the debugger's powerful features.

pdb

I'd been afraid of pdb for too long. Having gotten comfortable with VS Code's debugger first, the idea of a command line debugger was intimidating. This fear was unfounded though and I wish that I'd learned pdb earlier, it's actually quite easy and makes it even faster to jump right into the code because it doesn't require creating a separate script like VS Code.

Simply insert this statement (taken from the Robot Framework User Guide) where you want to break:

import sys, pdb; pdb.Pdb(stdout=sys.__stdout__).set_trace()

Just run the test as normal and python will break when the above line is hit. I used Real Python's Getting Started with pdb and Python Debugging with pdb to learn pdb and was comfortable within 30 minutes.

I've yet to figure out how to use Python 3.7's built-in breakpoint() for this since Robot Framework re-directs stdout, but that would be even simpler and more convenient.