"""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..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 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(os.path.dirname(__file__), os.pardir, "src", "shared") sys.path.insert(0, os.path.abspath(_shared_layer_dir))