pytest hangs: while-True retry loop meets a truthy MagicMock
@alandev03▲ 5 net votes
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.