mirror of
https://github.com/Sea-Haven-Industries/procurement-ingest.git
synced 2026-10-07 16:08:54 +00:00
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
This commit is contained in:
parent
25b7fc188d
commit
0280109e76
1 changed files with 9 additions and 0 deletions
|
|
@ -29,8 +29,17 @@ def load_handler(relative_path, module_name):
|
||||||
across Lambdas. The same loader serves the ``ses_auth.py`` modules,
|
across Lambdas. The same loader serves the ``ses_auth.py`` modules,
|
||||||
which are likewise duplicated per pipeline and not importable as
|
which are likewise duplicated per pipeline and not importable as
|
||||||
packages.
|
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
|
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)
|
spec = importlib.util.spec_from_file_location(module_name, path)
|
||||||
module = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
sys.modules[module_name] = module
|
sys.modules[module_name] = module
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue