From 0280109e7691f663bb6144e51cae8e32dc849b94 Mon Sep 17 00:00:00 2001 From: Adam Moussa Date: Wed, 15 Jul 2026 20:18:49 -0400 Subject: [PATCH] Load Lambda function dir on sys.path in tests Rebasing INFRA-107 onto main folded #95's pytest suite into this branch's tests. The unified conftest loads the PO/WO handlers by file path, and handler.py now does `from ses_auth import authenticate_inbound_email` -- a bare sibling import that resolves in the Lambda only because the runtime puts each function's own directory on sys.path. The shared load_handler now adds that directory so the handler tests import correctly alongside the sender-auth tests. Refs: INFRA-107 --- tests/conftest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index f50a313..de58e0f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -29,8 +29,17 @@ def load_handler(relative_path, module_name): across Lambdas. The same loader serves the ``ses_auth.py`` modules, which are likewise duplicated per pipeline and not importable as packages. + + The Lambda runtime puts each function's own directory on ``sys.path``, + so handler modules import their siblings by bare name (e.g. + ``from ses_auth import authenticate_inbound_email``). The function + directory is added to ``sys.path`` here so the module executes the + same way under test as it does in the Lambda. """ path = REPO_ROOT / relative_path + package_dir = str(path.parent) + if package_dir not in sys.path: + sys.path.insert(0, package_dir) spec = importlib.util.spec_from_file_location(module_name, path) module = importlib.util.module_from_spec(spec) sys.modules[module_name] = module