Skip to content

Commit 6943614

Browse files
committed
chore: work on ci-cd integration
1 parent 2104a26 commit 6943614

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

azure_ai/tests/test_azureml_workspace.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22
Test script to verify Azure ML installation is working properly.
33
"""
44

5+
from logging import getLogger
6+
57
from azure_ai.ml_studio import AzureAIMLWorkspace
68

79
from .test_base import AzureMLTestBase
810

911

12+
logger = getLogger(__name__)
13+
14+
1015
class AzureMLTestWorkspace(AzureMLTestBase):
1116
"""Base class for all unit tests."""
1217

1318
def test_azureml_workspace(self):
1419
"""Test that we can create and use an Azure ML workspace."""
1520

1621
if not self.is_testable:
22+
logger.warning("Skipping test_azureml_workspace() as the environment is not testable.")
1723
return
1824

1925
workspace = AzureAIMLWorkspace()

azure_ai/tests/test_base.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import unittest
77
from logging import getLogger
8+
from unittest.mock import patch
89

910
from dotenv import load_dotenv
1011

@@ -24,4 +25,48 @@ def setUpClass(cls):
2425
"""Set up class-level resources."""
2526
if not cls.is_testable:
2627
logger.warning("CI - skipping tests that require Azure ML workspace connection")
28+
cls._setup_azure_mocks()
2729
return
30+
31+
@classmethod
32+
def tearDownClass(cls):
33+
"""Clean up class-level resources."""
34+
if not cls.is_testable:
35+
# Stop all patches
36+
patchers = [
37+
"ml_client_patcher",
38+
"credential_patcher",
39+
"dataset_v2_patcher",
40+
"workspace_patcher",
41+
"dataset_v1_patcher",
42+
"compute_patcher",
43+
"experiment_patcher",
44+
]
45+
for patcher_name in patchers:
46+
if hasattr(cls, patcher_name):
47+
getattr(cls, patcher_name).stop()
48+
49+
@classmethod
50+
def _setup_azure_mocks(cls):
51+
"""Set up mocks for Azure ML clients when not testable."""
52+
logger.info("Setting up Azure ML mocks for non-testable CI-CD environment")
53+
54+
# Patch at the source before any imports happen
55+
cls.ml_client_patcher = patch("azure.ai.ml.MLClient")
56+
cls.mock_ml_client = cls.ml_client_patcher.start()
57+
58+
cls.credential_patcher = patch("azure.identity.DefaultAzureCredential")
59+
cls.mock_credential = cls.credential_patcher.start()
60+
61+
# Also patch other Azure classes at their source
62+
cls.workspace_patcher = patch("azureml.core.Workspace")
63+
cls.mock_workspace = cls.workspace_patcher.start()
64+
65+
cls.dataset_v1_patcher = patch("azureml.core.Dataset")
66+
cls.mock_dataset_v1 = cls.dataset_v1_patcher.start()
67+
68+
cls.compute_patcher = patch("azureml.core.compute.AmlCompute")
69+
cls.mock_compute = cls.compute_patcher.start()
70+
71+
cls.experiment_patcher = patch("azureml.core.Experiment")
72+
cls.mock_experiment = cls.experiment_patcher.start()

azure_ai/tests/test_cluster.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
"""
44

55
import os
6+
from logging import getLogger
67

78
from azure_ai.ml_studio import AzureAIMLStudioComputeCluster
89

910
from .test_base import AzureMLTestBase
1011

1112

1213
HERE = os.path.abspath(os.path.dirname(__file__))
14+
logger = getLogger(__name__)
1315

1416

1517
class AzureMLTestCluster(AzureMLTestBase):
@@ -22,6 +24,7 @@ def test_existing_cluster(self):
2224
or create it if it does not.
2325
"""
2426
if not self.is_testable:
27+
logger.warning("Skipping test_existing_cluster() as the environment is not testable.")
2528
return
2629

2730
cluster = AzureAIMLStudioComputeCluster(cluster_name="standard-cluster")

azure_ai/tests/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def test_workspace_connection(self):
7878
"""Test workspace connection using config.json."""
7979

8080
if not self.is_testable:
81+
logger.warning("Skipping test_workspace_connection() as the environment is not testable.")
8182
return
8283

8384
try:

azure_ai/tests/test_dataset.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
"""
44

55
import os
6+
from logging import getLogger
67

78
from azure_ai.ml_studio import AzureAIMLAssetsDataset
89

910
from .test_base import AzureMLTestBase
1011

1112

1213
HERE = os.path.abspath(os.path.dirname(__file__))
14+
logger = getLogger(__name__)
1315

1416

1517
class AzureMLTestDataset(AzureMLTestBase):
@@ -18,6 +20,7 @@ class AzureMLTestDataset(AzureMLTestBase):
1820
def test_existing_dataset(self):
1921
"""Test that we can create and use an Azure ML workspace."""
2022
if not self.is_testable:
23+
logger.warning("Skipping test_existing_dataset() as the environment is not testable.")
2124
return
2225

2326
dataset = AzureAIMLAssetsDataset(
@@ -31,6 +34,7 @@ def test_kaggle_dataset(self):
3134
https://www.kaggle.com/datasets/whenamancodes/student-performance
3235
"""
3336
if not self.is_testable:
37+
logger.warning("Skipping test_kaggle_dataset() as the environment is not testable.")
3438
return
3539

3640
dataset = AzureAIMLAssetsDataset(
@@ -50,6 +54,7 @@ def test_file_dataset(self):
5054
"""
5155

5256
if not self.is_testable:
57+
logger.warning("Skipping test_file_dataset() as the environment is not testable.")
5358
return
5459

5560
dataset = AzureAIMLAssetsDataset(

0 commit comments

Comments
 (0)