pdb: Debugging Test Failures
The pdb module is the Python debugger in the standard library. You use --pdb to have pytest start a debugging session at the point of failure. Let’s look at pdb in action in the context of the Tasks project.
In Parametrizing Fixtures, we left the Tasks project with a few failures:
| $ cd /path/to/code/ch3/c/tasks_proj |
| $ pytest --tb=no -q |
| .........................................FF.FFFF |
| FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.FFF........... |
| 42 failed, 54 passed in 4.74 seconds |
Before we look at how pdb can help us debug this test, let’s take a look at the pytest options available to help speed up debugging test failures, which we first looked at in Using Options:
- --tb=[auto/long/short/line/native/no] ...
Get Python Testing with pytest now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.