You can add a breakpoint in pytest using `--pdb`

When debugging failing tests, pytest has built-in support for dropping into Python’s debugger (pdb) automatically when a test fails or at specific breakpoints.

Run pytest with the --pdb flag:

pytest --pdb

This will pause execution and open an interactive pdb session whenever a test fails, allowing you to inspect variables, step through code, and understand what went wrong.

For manual breakpoints, add this to your test code:

def test_something():
    result = complex_calculation()
    breakpoint()  # Drops into pdb here
    assert result == expected

Useful pdb commands:

This is especially helpful when trying to understand why a test is failing or to explore the state of your application during test execution.

Original source