Skip to content

Commit 475f90f

Browse files
committed
test updates
1 parent 217436b commit 475f90f

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

lib/idp_common_pkg/tests/unit/test_delete_tests.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414
sys.modules["idp_common_pkg"] = Mock()
1515
sys.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

lib/idp_common_pkg/tests/unit/test_results_resolver.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@
88

99
import 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

0 commit comments

Comments
 (0)