Debugging with pdb
pdb,[49] which stands for “Python debugger,” is part of the Python standard library, so we don’t need to install anything to use it. We’ll get pdb up and running and then look at some of the most useful commands within pdb.
You can launch pdb from pytest in a few different ways:
-
Add a breakpoint() call to either test code or application code. When a pytest run hits a breakpoint() function call, it will stop there and launch pdb.
-
Use the --pdb flag. With --pdb, pytest will stop at the point of failure. In our case, that will be at the assert len(the_list) == 2 line.
-
Use the --trace flag. With --trace, pytest will stop at the beginning of each test.
For our purposes, combining --lf and --trace will work perfectly. The combo ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access