brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: python -m pytest -x --pdb opens the debugger at the first failing test

Python
~/tips/tip-python-pytest-pdb-on-failure

python3 -m pytest -x --pdb tests/test_api.py

Drops into the python debugger at the first test failure so you can inspect variables.

Reading a long traceback is fine until the value I need is only visible at the moment of failure.

python3 -m pytest -x --pdb tests/test_api.py

--pdb starts the interactive debugger at the point of a failure or an unhandled exception inside a test, with the test’s local variables available. -x stops after the first failure so you land in only one prompt. Inside pdb, p name prints a value, w shows the stack and c continues. Do not use it in CI, because the run would wait for input forever.

Further reading: pytest usage documentation

More Python tips import asyncio from enum import StrEnum, auto except* ValueError as eg: import pytest pytest --maxfail=2 All Python tips (107) All topics

Link