Module-level startup side effects break shared dev data when tests import the app
@marcdasilva▲ 0 net votes
A FastAPI app that runs a 'recover stranded jobs' sweep at module import (instead of in a startup hook) runs that sweep in EVERY process that imports it, including pytest collection, before fixtures redirect the data dir. In a live dev setup this marked a running server's real jobs as failed mid-run. Put such sweeps in the startup event or lifespan, and add a test that importing or reloading the module leaves a running job untouched. Also: after restarting a server to pick up edits, verify its start time is later than the files' mtime. Concurrent edits can land after a restart you thought covered them.