File tree Expand file tree Collapse file tree 2 files changed +30
-18
lines changed
lib/idp_common_pkg/tests/unit Expand file tree Collapse file tree 2 files changed +30
-18
lines changed Original file line number Diff line number Diff line change 1414sys .modules ["idp_common_pkg" ] = Mock ()
1515sys .modules ["idp_common_pkg.logger" ] = Mock ()
1616
17- # Add the lambda directory to the path for importing
18- lambda_path = os .path .join (
19- os .path .dirname (__file__ ), "../../../../src/lambda/delete_tests"
20- )
21- sys .path .insert (0 , lambda_path )
17+ # Mock boto3 before importing the Lambda module to prevent NoRegionError
18+ # The Lambda creates boto3 clients at module level which requires AWS region
19+ with patch ("boto3.resource" ) as mock_resource , patch ("boto3.client" ) as mock_client :
20+ mock_resource .return_value = Mock ()
21+ mock_client .return_value = Mock ()
22+
23+ # Add the lambda directory to the path for importing
24+ lambda_path = os .path .join (
25+ os .path .dirname (__file__ ), "../../../../src/lambda/delete_tests"
26+ )
27+ sys .path .insert (0 , lambda_path )
2228
23- import index # type: ignore[import-untyped] # noqa: E402
29+ import index # type: ignore[import-untyped] # noqa: E402
2430
2531
2632@pytest .mark .unit
Original file line number Diff line number Diff line change 88
99import pytest
1010
11- # Import the specific lambda module using importlib to avoid conflicts
12- spec = importlib .util .spec_from_file_location (
13- "results_index" ,
14- os .path .join (
15- os .path .dirname (__file__ ),
16- "../../../../src/lambda/test_results_resolver/index.py" ,
17- ),
18- )
19- if spec is None or spec .loader is None :
20- raise ImportError ("Could not load test_results_resolver module" )
21- index = importlib .util .module_from_spec (spec )
22- spec .loader .exec_module (index )
11+ # Mock boto3 before importing the Lambda module to prevent NoRegionError
12+ # The Lambda creates boto3 clients at module level which requires AWS region
13+ with patch ("boto3.resource" ) as mock_resource , patch ("boto3.client" ) as mock_client :
14+ mock_resource .return_value = Mock ()
15+ mock_client .return_value = Mock ()
16+
17+ # Import the specific lambda module using importlib to avoid conflicts
18+ spec = importlib .util .spec_from_file_location (
19+ "results_index" ,
20+ os .path .join (
21+ os .path .dirname (__file__ ),
22+ "../../../../src/lambda/test_results_resolver/index.py" ,
23+ ),
24+ )
25+ if spec is None or spec .loader is None :
26+ raise ImportError ("Could not load test_results_resolver module" )
27+ index = importlib .util .module_from_spec (spec )
28+ spec .loader .exec_module (index )
2329
2430
2531@pytest .mark .unit
You can’t perform that action at this time.
0 commit comments