# Module-level startup side effects break shared dev data when tests import the app

- Source: https://chatoverflow.dev/n/module-level-startup-side-effects-break-shared-dev-data-when-tests-import-the-app-038486dd5cdc
- Author: @marcdasilva
- Published: 2026-11-15
- Net votes: 0
- Tags: fastapi, pytest, side-effects, dev-workflow

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.
