Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging with pycharm, how to step into project, without entering django libraries

Think about this scenario:

I debug my Django project and I step through the code (in and out). The debugger sometimes enters Django libraries or other external libraries.

Does anyone know how to prevent the debugger from entering external code? Or at least a 'big' step out to get the debugger back to the project code?

like image 594
Dan Avatar asked Mar 01 '13 18:03

Dan


People also ask

How do I step in PyCharm debugger?

Force step overFrom the main menu, select Run | Force Step Over or press Alt+Shift+F8 .

How do I enable debugging actions in PyCharm?

Just right-click any line in the editor and select the Debug <filename> command from the context menu. After the program has been suspended, use the debugger to get the information about the state of the program and how it changes during running.

What is step into and step over in debugging?

Ans: Step Into: Step Into is used for debugging the test steps line by line. When the procedure gets called, Step Into enables you to get inside the procedure and debugs the procedure steps line by line. Step Over: Step Over will enable, only after the debugging is started with Step Into / Run From Step / Run to Step.


Video Answer


2 Answers

Does anyone know how to prevent the debugger from entering external code?

Yes, Dmitry Trofimov knows;

(...) add modules you don't want to trace to the dict DONT_TRACE in <pycharm-distr>/helpers/pydev/pydevd.py
That is a hacky solution (...)

If you want this feature to be less hacky you can vote on it by visiting issue
PY-9101 Implement "Do not step into the classes" option for Python debugger


Those using pdb might be interested to know there is such a feature in pdb;

Starting with Python 3.1, Pdb class has a new argument called skip -

class pdb.Pdb(completekey='tab', stdin=None, stdout=None, skip=None, nosigint=False)

The skip argument, if given, must be an iterable of glob-style module name patterns. The debugger will not step into frames that originate in a module that matches one of these patterns. 1

1 Whether a frame is considered to originate in a certain module is determined by the __name__ in the frame globals.

The example given in the docs shows how to skip Django's packages -

import pdb; pdb.Pdb(skip=['django.*']).set_trace()

like image 90
Piotr Dobrogost Avatar answered Oct 01 '22 13:10

Piotr Dobrogost


Everything looks the same to the debugger, it can't distinguish between your code or Django's code – it's all Python. So it will run everything, however if you want to stop it from drilling down so low you'll have to start “stepping over” lines of code instead of “stepping into” them.

According to the PyCharm docs you'll want to use F8 when ever you see a line of code that looks like it could be a gateway into Django's internals. If you accidently find yourself inside Django's source code you can hit Shift+F8 until you're out of it.

like image 22
Matt Deacalion Avatar answered Oct 01 '22 13:10

Matt Deacalion