conftest.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. """Monorepo test bootstrap — make sibling packages importable.
  2. After lambdagent moved to src-layout (``lambdagent/src/lambdagent``),
  3. we need TWO entries on sys.path:
  4. 1. Monorepo root — so ``from agentpaas.X``, ``from agentexample.X``,
  5. ``from lambdagent_guard.X`` (other siblings) resolve.
  6. 2. ``lambdagent/src`` — so ``from lambdagent.X`` resolves directly to
  7. the local source tree instead of requiring ``pip install -e .``.
  8. The pip-install path is still preferred for production (see setup.sh and
  9. Dockerfile); this conftest only smoothes local ``pytest tests/`` runs
  10. during development.
  11. """
  12. import os
  13. import sys
  14. _MONOREPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  15. _LAMBDAGENT_SRC = os.path.join(_MONOREPO_ROOT, "lambdagent", "src")
  16. # Order matters: src first (more specific), monorepo root second.
  17. for _p in (_LAMBDAGENT_SRC, _MONOREPO_ROOT):
  18. if _p not in sys.path:
  19. sys.path.insert(0, _p)
  20. # Critical: disable startup-time auto-bootstrap during tests.
  21. # Without this, every `TestClient(app)` would fire the desktop bootstrap
  22. # hook, write a fresh API key to the developer's real
  23. # ~/.agentpaas/config.json, and pollute the system DB with phantom tenants.
  24. # Tests that want to exercise the bootstrap path do so explicitly via
  25. # `auto_bootstrap_desktop()` with CONFIG_FILE patched to a tmp path
  26. # (see test_deployment_mode.py).
  27. os.environ.setdefault("AGENTPAAS_TESTING", "1")