Python Debugger which supports Black Boxing?
Asked Answered
M

2

6

If I use the debugger, most of the times I just want to see what the interpreter does in my code. I want to step over all code of the framework and libraries I use.

AFAIK this is called Black Boxing.

How can I do this with Python ipdb or an other Python debugger?

Imagine this:

I use a orm framework which I trust, and don't want to debug.

cut_hair_method(orm_object.user)

The method cut_hair_method() is mine, and I want to debug it.

The orm_object is from the framework I use. The debugger will step into the orm-code and do some special things, which I don't care about. I have no way to tell the debugger: Don't jump into the orm code!

Update

For my case it would be very easy to decide which code should be in the black box and which code not: Code in $VIRTUAL_ENV/src/ is not in the black box, all other code is. Except I explicitly tell the debugger something else.

Update2

I have the name "Black Boxing" from this article: https://hacks.mozilla.org/2013/08/new-features-of-firefox-developer-tools-episode-25/

Muller answered 11/12, 2014 at 8:35 Comment(7)
Any good debugger will feature "step over" commands. Black-Boxing is far more than just debugging. Black-boxing is an idea centered around how to test (and not debug) applications.Alcahest
I added an example. AFAIK "step over" is not possible everywhere.Muller
Instead of using step-over if that isn't working for you - why not set a break point in the `cut_hair_method, and then run.... I seem to remember the IDLE IDE had a blacklist of modules not to step through, but i also seem to remember it didn't work too well (when i used it several years ago - i might be wrong though).Alcahest
@TonySuffolk66 I know how to use a debugger with step-over step-into since about 20 years (first one was turbo pascal). I know how to set breakpoints, but it just does not feel like flying. It is cumbersome.Muller
Just use r to return from the ORM call. It is really not that hard. s into orm_object.user, r step out again and straight into cut_hair_method().Setscrew
It's a valid question, without an easy answer. I too would like to configure simple, understandable heuristics to automatically step into vs step over depending on what current point is. Perhaps it by module, perhaps something else. Most debuggers are scriptable, attach a test to current frame after step and finish/return if you don't like it.Childbed
I opened a feature request for PyCharm: youtrack.jetbrains.com/issue/PY-14789Muller
L
5

The Python debugger base class (bdb.Bdb) has an a .skip attribute, giving a list of module names to skip over. You can provide this list either when instantiation the debugger, or later. If you want to provide a negative list (list of module that are your own), or otherwise compute whether a module should be skipped, you can subclass the debugger class and override is_skipped_module.

Lactoprotein answered 20/12, 2014 at 15:5 Comment(0)
M
0

Since PyCharm version 4.5 there is a feature called "Step into my code": https://www.jetbrains.com/pycharm/whatsnew/#StepIntoCode

It works. I my case, I just want to step into my code (Django application), but not into the code of django itself. The default short-cut is complicated (alt-shift-F7) but it is easy to change it.

Related issue: https://youtrack.jetbrains.com/issue/PY-14789

Muller answered 19/5, 2015 at 8:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.