Không nên để test dùng chung production database. Dùng test database riêng, transaction rollback, fixture tạo schema, hoặc container database tùy mức integration.
Với dependency DB session, test có thể override dependency để inject session test:
python
async def override_db():
async with TestSessionLocal() as session:
yield session
app.dependency_overrides[get_db] = override_dbCần đảm bảo isolation giữa tests: reset data, rollback transaction hoặc tạo database/schema riêng cho từng test worker.