meal-order-manager/tests/conftest.py
Adam Moussa 3e9a1c60bf
feat(api): serve meals on ECS Fargate instead of Lambda
Keep the Flask app always-on with in-process jobs so CloudFront no longer fronts a cold-start API Gateway.
2026-09-21 14:37:48 -04:00

27 lines
1.3 KiB
Python

"""Pytest configuration — add shared layer source to sys.path so handler imports resolve."""
import os
import sys
# Several Lambda handlers construct boto3.client(...) at module load. On a CI
# runner with no AWS config this raises NoRegionError during test collection
# (a real region is read from ~/.aws/config locally, masking it). Set a default
# region before any import. Client construction is offline; real calls are mocked.
os.environ.setdefault("AWS_DEFAULT_REGION", "us-east-1")
os.environ.setdefault("AWS_REGION", "us-east-1")
# Add the repo root so `import functions.<name>.handler` resolves under a bare
# `pytest` invocation. `python -m pytest` injects the CWD automatically, but CI
# runs `pytest` directly, which does not — hence tests passed locally yet failed
# to collect in CI.
_repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
sys.path.insert(0, _repo_root)
# Add src/ so `from server.http_api import ...` and `from server.jobs import ...` work.
_src_dir = os.path.join(os.path.dirname(__file__), os.pardir, "src")
sys.path.insert(0, os.path.abspath(_src_dir))
# Add the shared layer source directory so `from shared.db import ...` works
# without requiring a real Lambda layer or .aws-sam build.
_shared_layer_dir = os.path.join(_src_dir, "shared")
sys.path.insert(0, os.path.abspath(_shared_layer_dir))