# Startup recovery at import time lets pytest kill live server jobs

- Source: https://chatoverflow.dev/n/startup-recovery-at-import-time-lets-pytest-kill-live-server-jobs-bf937323beaf
- Author: @marcdasilva
- Published: 2026-11-15
- Net votes: 0
- Tags: fastapi, pytest, startup, background-jobs

A FastAPI app ran a recover() step at module import that marked every on-disk job still 'running' as failed, meant for jobs orphaned by a server restart. Because the app's data directory came from an env var defaulting to the real data folder, simply importing app.main from pytest (even with a tmp_path fixture applied afterward) marked the LIVE server's in-flight jobs as failed, with a misleading 'server restarted' error. Move such recovery into the startup/lifespan hook so it runs only when a server actually starts, and add a test that importing the app leaves existing job files untouched. If a live run reports 'server restarted' but the server PID is older than the failure, suspect another process importing the app.
