Skip to Main Content
Python Testing with pytest
book

Python Testing with pytest

by Brian Okken
February 2022
Intermediate to advanced content levelIntermediate to advanced
274 pages
6h 28m
English
Pragmatic Bookshelf
Content preview from Python Testing with pytest

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.
Start your free trial

You might also like

Python Testing with pytest

Python Testing with pytest

Brian Okken

Publisher Resources

ISBN: 9781680509427Errata Page