Skip to content

Commit b1d14de

Browse files
author
Mohamed Zeidan
committed
adjusted unit tests to mock k8s connectivity
1 parent 34ec068 commit b1d14de

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

test/unit_tests/cli/test_inference.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
import hyperpod_jumpstart_inference_template.registry as jreg
88
import hyperpod_custom_inference_template.registry as creg
99

10+
# Mock Kubernetes connectivity for all tests in this module
11+
@pytest.fixture(autouse=True)
12+
def mock_kubernetes_connectivity():
13+
"""Mock Kubernetes connectivity checks for all tests in this module."""
14+
with patch('sagemaker.hyperpod.common.cli_decorators._check_kubernetes_connectivity') as mock_connectivity, \
15+
patch('sagemaker.hyperpod.common.cli_decorators._is_kubernetes_operation') as mock_is_k8s_op:
16+
# Always return successful connectivity
17+
mock_connectivity.return_value = (True, "")
18+
# Let the operation detection work normally
19+
mock_is_k8s_op.side_effect = lambda func, **kwargs: True
20+
yield
21+
1022
# Import the non-create commands that don't need special handling
1123
from sagemaker.hyperpod.cli.commands.inference import (
1224
js_create, custom_create, custom_invoke,

test/unit_tests/cli/test_training.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,26 @@
1313
import sys
1414
import os
1515
import importlib
16+
import pytest
1617

1718
# Add the hyperpod-pytorch-job-template to the path for testing
1819
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', 'hyperpod-pytorch-job-template'))
1920

21+
# Mock Kubernetes connectivity for all tests in this module
22+
@pytest.fixture(autouse=True)
23+
def mock_kubernetes_connectivity():
24+
"""Mock Kubernetes connectivity checks for all tests in this module."""
25+
with patch('sagemaker.hyperpod.common.cli_decorators._check_kubernetes_connectivity') as mock_connectivity, \
26+
patch('sagemaker.hyperpod.common.cli_decorators._is_kubernetes_operation') as mock_is_k8s_op, \
27+
patch('sagemaker.hyperpod.common.cli_decorators._check_training_operator_exists') as mock_training_op:
28+
# Always return successful connectivity
29+
mock_connectivity.return_value = (True, "")
30+
# Let the operation detection work normally
31+
mock_is_k8s_op.side_effect = lambda func, **kwargs: True
32+
# Always return that training operator exists
33+
mock_training_op.return_value = True
34+
yield
35+
2036
try:
2137
from hyperpod_pytorch_job_template.v1_1.model import PyTorchJobConfig, VolumeConfig
2238
from pydantic import ValidationError

test/unit_tests/error_handling/test_cli_decorators.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121
_is_get_logs_operation
2222
)
2323

24+
# Mock Kubernetes connectivity for all tests in this module
25+
@pytest.fixture(autouse=True)
26+
def mock_kubernetes_connectivity():
27+
"""Mock Kubernetes connectivity checks for all tests in this module."""
28+
with patch('sagemaker.hyperpod.common.cli_decorators._check_kubernetes_connectivity') as mock_connectivity, \
29+
patch('sagemaker.hyperpod.common.cli_decorators._is_kubernetes_operation') as mock_is_k8s_op:
30+
# Always return successful connectivity
31+
mock_connectivity.return_value = (True, "")
32+
# Let the operation detection work normally
33+
mock_is_k8s_op.side_effect = lambda func, **kwargs: True
34+
yield
35+
2436

2537
class TestHandleCliExceptions:
2638
"""Test template-agnostic handle_cli_exceptions decorator."""

0 commit comments

Comments
 (0)