Jumping to the exact error line in Python

hi RF team,

I’m using the RobotCode extension. I wonder how to jump into the exact error line in a Python file. For example, I expect it to point to assert 1 == 2 in the Python keyword definition instead of stopping at the robot file.
Screenshot 2024-05-11 at 11.55.31 AM

Screenshot 2024-05-11 at 11.55.46 AM


Hi @Dex, what do you mean with jump to that error? At debugging time? Or after the test run?

hi @daniel,

I mean in runtime. Based on my screenshots, the error is raised at assert 1==2, but the VS Code stops at Python Keyword in the robot file, not the line assert 1 == 2 in the Python file.

Why do I need that? Consider the def python_keyword(numA, numB) is

assert numA == numB
assert numA + numB == numB
assert numA - numB == numB

VS code only stops at Python Keyword in the Robot file. I don’t know which assert raised the error. I was mad to find the root cause in the nested loop and nested if condition in my real case.

I tried to use debug but it doesn’t help also.

Search in the VSCode settings for robotcode.debug.attachPython and enable this setting. This attaches the python debugger to the robot run. Now you can set a breakpoint in the python code and the debugger should stop there and then you can step also through the python code.
if the debugger has stopped in python code, you can enable in the Debug side view at the bottom the `User Uncaughted Exceptions" automatic breakpoint and continue the debugger.
Play a little bit with this automatic breakpoints, but be carefull, because some breakpoints also stops in the system libraries, every time an exception occurs. You can click F5 oder Continue the debugger if that happens.

I did enable robotcode.debug.attachPython. Based on the example in my last comment, I put a breakpoint at assert numA == numB, and it stops there, but when I press continue, it jumps to the Robot print fail message function.
I think the feature I need is not available at this moment. Thanks for your work.

ok, if the debugger stops at the python break point, use “Step Over” F10 or "Step “Step Into” F11 to step trough the python code. Or use the Automatic Exception Breakpoint described above.

If you use assert python throws an exception, if the assertion fails, then it goes not to the next line of the code, instead the exception handler is called, that is somewhere hidden in the robot framework code, thats why the debugger stops in the robotcode after the exception.

Unbenanntes Video

what did you exactly expect?

1 Like

I missed the User Uncaught Exceptions option. The debugger works as expected now. Thanks for your video :v:

1 Like