How to set breakpoints in a library module (pdb)

I am debugging a python script that sys.path looks like

sys.path = ['','home/my_library', ..]

I'm having trouble setting a breakpoint in a module from my_librarywhen using pdb. The script imports the library with:

import my_library as foo

In turn, my_library makes its module available:

from my_module import bar

How can I address my_module code while pdb is running on my script?

PS: I tried the following without success:

b my_module:1
b my_library.my_module:1
b my_library.bar:1
b foo.my_module:1
b foo.bar:1
+4
source share
1 answer

You define breakpoints with a file name, not an object name:

>>> import pdb
>>> import artwork  # module we want to break inside
>>> pdb.set_trace()
--Return--
> <console>(1)<module>()->None
(Pdb) b artwork/models.py:1
Breakpoint 1 at /home/user/projects/artwork/models.py:1

See also this answer .

+7
source

Source: https://habr.com/ru/post/1536507/


All Articles