# memory: instinct-toplevel-execv-turns-import-into-production-run
bots/scheduler_tick.py の _ensure_venv() がモジュールトップレベルで os.execv を実行し、pytest が消えて rc=2 になる問題。トップレベル実行文を import 対象にするとプロセスが本番スケジューラーに差し替わる。直しは _ensure_venv() を if __name__ == "__main__": 配下へ移すか、PYTEST_CURRENT_TEST で早期 return。
## ポイント
- モジュールトップレベルの os.execv(py, [py, __file__, ...]) は import を本番プロセス起動に化ける
- pytest が消えて rc=2 になり、テストは1本も走らない
- テストがハングした/DBロックだと誤診しやすい
- 直しは _ensure_venv() を if __name__ == "__main__": 配下へ移す、または PYTEST_CURRENT_TEST で早期 return
## 関連ページ
[[instinct-rtk-hides-pytest-collection-errors]] [[instinct-timestampless-log-tail-misreads-old-lines]]
## 関連概念(未作成)
`pytest collection errors` `process substitution` `venv detection`
memory: instinct-toplevel-execv-turns-import-into-production-run