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/

guettli
  • 25,042
  • 81
  • 346
  • 663
  • 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. – Tony Suffolk 66 Dec 11 '14 at 08:41
  • I added an example. AFAIK "step over" is not possible everywhere. – guettli Dec 11 '14 at 08:56
  • 1
    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). – Tony Suffolk 66 Dec 11 '14 at 09:03
  • @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. – guettli Dec 11 '14 at 09:12
  • 1
    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()`. – Martijn Pieters Dec 18 '14 at 15:22
  • 1
    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. – Dima Tisnek Dec 19 '14 at 12:23
  • I opened a feature request for PyCharm: https://youtrack.jetbrains.com/issue/PY-14789 – guettli Dec 22 '14 at 13:48

2 Answers2

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.

Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
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

guettli
  • 25,042
  • 81
  • 346
  • 663