Using the Pdb+ debugger#

Learning Objectives#

After working through this topic, you should be able to:

  • Explain what a breakpoint is and how it helps with debugging

  • Set simple and conditional breakpoints in your code

  • Use the basic pdbp commands to navigate around while debugging

Materials#

Video:

Download the slides.

pdbp and different ways of running code#

The good news is that pdbp works well with our two main ways of running code: pytest and pytask. The bad news is that setting a breakpoint differs slightly across the different ways of running our code.

Breakpoint in simple py files#

Assume we have code in example.py and run it via python example.py. Then you set a breakpoint via import pdbp; breakpoint()

Breakpoints with pytest#

Assume we have code in test_example.py. Then you set a breakpoint via breakpoint(), i.e. without the import statement.

If you are in a repository created via the project templates, this is all you have to do because pytest will already be configured correctly.

If you are in another repository, you need to execute pytest with an additional option:

pytest --pdbcls=pdbp:Pdb

Breakpoints with pytask#

Assume we have code in task_example.py. Then you set a breakpoint via breakpoint(), i.e. without the import statement.

If you are in a repository created via the project templates, this is all you have to do because pytask will already be configured correctly.

If you are in another repository, you need to execute pytask with an additional option:

pytask --pdbcls=pdbp:Pdb

Additional Materials#

Quiz#