Questions tagged [pdb]

This tag refers to the Python debugger. For questions pertaining to the protein database file format, use the protein-database tag. For questions pertaining to Microsoft Program Database files, use the pdb-files tag.

The Python Debugger supports breakpoints, single stepping, inspection of stack frames, source code listing, and evaluation of arbitrary Python code in the context of any stack frame. It also supports post-mortem debugging and can be called under program control.

For questions pertaining to the protein database file format (.pdb), use the tag.

For questions pertaining to Microsoft "Program Database" (.pdb) files, use the tag.

880 questions
21
votes
2 answers

How to use pdb.set_trace() in a Django unittest?

I want to debug a Django TestCase just like I would any other Python code: Simply call pdb.set_trace() and then drop into an interactive session. When I do that, I don't see anything, as the tests are run in a different process. I'm using…
Brian Dant
  • 4,029
  • 6
  • 33
  • 47
19
votes
7 answers

How to make pdb recognize that the source has changed between runs?

From what I can tell, pdb does not recognize when the source code has changed between "runs". That is, if I'm debugging, notice a bug, fix that bug, and rerun the program in pdb (i.e. without exiting pdb), pdb will not recompile the code. I'll still…
user88028
  • 193
  • 1
  • 4
19
votes
2 answers

Use ipdb instead of pdb with py.test --pdb option

I want to use ipdb instead of pdb with py.test --pdb option. Is this possible? If so, how? Clearly, I can use import ipdb; ipdb.set_trace() in the code but that requires to run the test, watch it fail, open a file, find the point of failure in said…
Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156
19
votes
5 answers

Can I get Python debugger pdb to output with Color?

I'm using PDB a lot and it seems it would be even better if I could add systax highlighting in color. Ideally, I'd like to have to the path to the code a lighter color. The line of actual code would be syntax highlighted. I'm using OS X and the…
BryanWheelock
  • 12,146
  • 18
  • 64
  • 109
19
votes
1 answer

Weird IPython ipdb behaviour

I have some really weird behaviour that I just don't understand and therefore cannot explain, so I hope someone here can help me out. First thing I noticed was ipdb not letting me define variables any more: ipdb> what=5 ipdb> what *** NameError:…
marue
  • 5,588
  • 7
  • 37
  • 65
18
votes
2 answers

How do I change a value while debugging python with pdb?

I want to run pdb, step through the code, and at some point change the value pointed at by some name. So I might want to change the value pointed at by the name 'stationLat'. But it seems I can't. Here's the example: >>> import…
Andrej Panjkov
  • 1,448
  • 2
  • 13
  • 17
18
votes
3 answers

PyCharm: how to do post mortem debugging in the ipython interactive console?

I've just started using the nice PyCharm community edition IDE, and can't do a simple thing that is part of my usual Python workflow. I've started an ipython console and I can import my modules and interactively run commands. In PyCharm when I…
neves
  • 33,186
  • 27
  • 159
  • 192
18
votes
1 answer

How to set breakpoints in a library module (pdb)

I am debugging a python script which sys.path looks like sys.path = ['','home/my_library', ..] I'm having troubles to set a breakpoint in a module from my_library while using pdb. The script imports the library with: import my_library as foo In…
Niccolò
  • 2,854
  • 4
  • 24
  • 38
18
votes
6 answers

How to watch for a variable change in python without dunder setattr or pdb

There is large python project where one attribute of one class just have wrong value in some place. It should be sqlalchemy.orm.attributes.InstrumentedAttribute, but when I run tests it is constant value, let's say string. There is some way to run…
Bunyk
  • 7,635
  • 8
  • 47
  • 79
17
votes
4 answers

How to define a new function in pdb

Why can't I define new functions when I run pdb? For example take myscript.py: #!/gpfs0/export/opt/anaconda-2.3.0/bin/python print "Hello World" print "I see you" If I run python -m pdb myscript.py and try to interactively define a new function:…
irritable_phd_syndrome
  • 4,631
  • 3
  • 32
  • 60
17
votes
3 answers

Debugging flask with pdb

I'm trying to use pdb to debug flask application. Setting break point is easy; I just use b index to break when index() is invoked or b 44 to set a break point at line 44. Breakpoint works with b 44 which is the start of the main, but b index…
prosseek
  • 182,215
  • 215
  • 566
  • 871
16
votes
1 answer

How to run pytest with an python debugger with tab completion?

Background I have been debugging my python scripts for ~2 years with plain from IPython import embed; embed(), and it has been working really fine. I just place the command on the line I want to examine, and when running the script I will have full…
Niko Föhr
  • 28,336
  • 10
  • 93
  • 96
16
votes
5 answers

Is there a way to step into decorated functions, skipping decorator code

I have a module which decorates some key functions with custom decorators. Debugging these functions with pdb often is a bit of a pain, because every time I step into a decorated function I first have to step through the decorator code itself. I…
href_
  • 1,509
  • 16
  • 15
15
votes
1 answer

assign values to symbols in python debugger (pdb)

Using pdb.set_trace(), I am trying to debug a series of expression in which j is used as an indexing variable. statements such as j = 0 are not allowed since j is a reserved symbol for pdb. How can I get around this?
hatmatrix
  • 42,883
  • 45
  • 137
  • 231
15
votes
2 answers

How to run pdb inside a Docker Container

I clearly don't understand something here. I am trying to run the pdb debugger interactively w/in a Docker Container. Here is some code: Dockerfile: FROM python:3.6 ENV PROJECT_DIR=/opt/foo WORKDIR $PROJECT_DIR COPY . . RUN pip install -r…
trubliphone
  • 4,132
  • 3
  • 42
  • 66