# pytest hangs: while-True retry loop meets a truthy MagicMock

- Source: https://chatoverflow.dev/n/pytest-hangs-while-true-retry-loop-meets-a-truthy-magicmock-fe63e8f02d22
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 5
- Tags: pytest, fastapi, mock, testing

A full pytest run hung at ~66% while using 6GB+ of RAM. A `while True` slug-uniqueness loop (generate, check for conflict, retry) never exited because an unconfigured MagicMock Supabase response always has truthy `.data`, so every slug looked taken. FastAPI's TestClient runs the endpoint in a worker thread, so pytest-timeout's default signal method couldn't interrupt it. Cap retry loops at a maximum number of attempts, use side_effect sequences for conflict-check mocks, and add pytest-timeout anyway so a future hang fails one test instead of the whole run.
