@@ -446,11 +446,13 @@ def test_submit_with_auto_cluster(mocker):
446446
447447def test_namespace_auto_detection_success (mocker ):
448448 """Test successful namespace auto-detection."""
449+ mocker .patch ("kubernetes.config.load_kube_config" )
449450 mocker .patch (
450451 "codeflare_sdk.ray.rayjobs.rayjob.get_current_namespace" ,
451452 return_value = "detected-ns" ,
452453 )
453454 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
455+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
454456
455457 rayjob = RayJob (
456458 job_name = "test-job" , entrypoint = "python script.py" , cluster_name = "test-cluster"
@@ -461,10 +463,12 @@ def test_namespace_auto_detection_success(mocker):
461463
462464def test_namespace_auto_detection_fallback (mocker ):
463465 """Test that namespace auto-detection failure raises an error."""
466+ mocker .patch ("kubernetes.config.load_kube_config" )
464467 mocker .patch (
465468 "codeflare_sdk.ray.rayjobs.rayjob.get_current_namespace" , return_value = None
466469 )
467470 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
471+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
468472
469473 with pytest .raises (ValueError , match = "Could not auto-detect Kubernetes namespace" ):
470474 RayJob (
@@ -476,11 +480,13 @@ def test_namespace_auto_detection_fallback(mocker):
476480
477481def test_namespace_explicit_override (mocker ):
478482 """Test that explicit namespace overrides auto-detection."""
483+ mocker .patch ("kubernetes.config.load_kube_config" )
479484 mocker .patch (
480485 "codeflare_sdk.ray.rayjobs.rayjob.get_current_namespace" ,
481486 return_value = "detected-ns" ,
482487 )
483488 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
489+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
484490
485491 rayjob = RayJob (
486492 job_name = "test-job" ,
@@ -494,7 +500,9 @@ def test_namespace_explicit_override(mocker):
494500
495501def test_shutdown_behavior_with_cluster_config (mocker ):
496502 """Test that shutdown_after_job_finishes is True when cluster_config is provided."""
503+ mocker .patch ("kubernetes.config.load_kube_config" )
497504 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
505+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
498506
499507 from codeflare_sdk .ray .rayjobs .config import ManagedClusterConfig
500508
@@ -512,7 +520,9 @@ def test_shutdown_behavior_with_cluster_config(mocker):
512520
513521def test_shutdown_behavior_with_existing_cluster (mocker ):
514522 """Test that shutdown_after_job_finishes is False when using existing cluster."""
523+ mocker .patch ("kubernetes.config.load_kube_config" )
515524 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
525+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
516526
517527 rayjob = RayJob (
518528 job_name = "test-job" ,
@@ -526,7 +536,9 @@ def test_shutdown_behavior_with_existing_cluster(mocker):
526536
527537def test_rayjob_with_rayjob_cluster_config (mocker ):
528538 """Test RayJob with the new ManagedClusterConfig."""
539+ mocker .patch ("kubernetes.config.load_kube_config" )
529540 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
541+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
530542
531543 from codeflare_sdk .ray .rayjobs .config import ManagedClusterConfig
532544
@@ -549,7 +561,9 @@ def test_rayjob_with_rayjob_cluster_config(mocker):
549561
550562def test_rayjob_cluster_config_validation (mocker ):
551563 """Test validation of ManagedClusterConfig parameters."""
564+ mocker .patch ("kubernetes.config.load_kube_config" )
552565 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
566+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
553567
554568 from codeflare_sdk .ray .rayjobs .config import ManagedClusterConfig
555569
@@ -621,7 +635,9 @@ def test_build_ray_cluster_spec_integration(mocker):
621635
622636def test_rayjob_with_runtime_env (mocker ):
623637 """Test RayJob with runtime environment configuration."""
638+ mocker .patch ("kubernetes.config.load_kube_config" )
624639 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
640+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
625641
626642 runtime_env = {"pip" : ["numpy" , "pandas" ]}
627643
@@ -642,7 +658,9 @@ def test_rayjob_with_runtime_env(mocker):
642658
643659def test_rayjob_with_active_deadline_and_ttl (mocker ):
644660 """Test RayJob with both active deadline and TTL settings."""
661+ mocker .patch ("kubernetes.config.load_kube_config" )
645662 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
663+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
646664
647665 rayjob = RayJob (
648666 job_name = "test-job" ,
@@ -664,7 +682,9 @@ def test_rayjob_with_active_deadline_and_ttl(mocker):
664682
665683def test_rayjob_cluster_name_generation_with_config (mocker ):
666684 """Test cluster name generation when using cluster_config."""
685+ mocker .patch ("kubernetes.config.load_kube_config" )
667686 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
687+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
668688
669689 from codeflare_sdk .ray .rayjobs .config import ManagedClusterConfig
670690
@@ -684,7 +704,9 @@ def test_rayjob_cluster_name_generation_with_config(mocker):
684704
685705def test_rayjob_namespace_propagation_to_cluster_config (mocker ):
686706 """Test that job namespace is propagated to cluster config when None."""
707+ mocker .patch ("kubernetes.config.load_kube_config" )
687708 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
709+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
688710
689711 from codeflare_sdk .ray .rayjobs .rayjob import get_current_namespace
690712
@@ -719,7 +741,9 @@ def test_rayjob_error_handling_invalid_cluster_config(mocker):
719741
720742def test_rayjob_constructor_parameter_validation (mocker ):
721743 """Test constructor parameter validation."""
744+ mocker .patch ("kubernetes.config.load_kube_config" )
722745 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
746+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
723747
724748 # Test with valid parameters
725749 rayjob = RayJob (
@@ -941,7 +965,9 @@ def test_build_ray_cluster_spec_with_image_pull_secrets(mocker):
941965
942966def test_rayjob_user_override_shutdown_behavior (mocker ):
943967 """Test that user can override the auto-detected shutdown behavior."""
968+ mocker .patch ("kubernetes.config.load_kube_config" )
944969 mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
970+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
945971
946972 # Test 1: User overrides shutdown to True even when using existing cluster
947973 rayjob_existing_override = RayJob (
@@ -1009,6 +1035,7 @@ def test_submit_with_cluster_config_compatible_image_passes(self, mocker):
10091035 """Test that submission passes with compatible cluster_config image."""
10101036 mocker .patch ("kubernetes.config.load_kube_config" )
10111037 mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1038+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
10121039 mock_api_instance = MagicMock ()
10131040 mock_api_class .return_value = mock_api_instance
10141041 mock_api_instance .submit_job .return_value = True
@@ -1030,6 +1057,7 @@ def test_submit_with_cluster_config_incompatible_image_fails(self, mocker):
10301057 """Test that submission fails with incompatible cluster_config image."""
10311058 mocker .patch ("kubernetes.config.load_kube_config" )
10321059 mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1060+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
10331061 mock_api_instance = MagicMock ()
10341062 mock_api_class .return_value = mock_api_instance
10351063
@@ -1052,6 +1080,7 @@ def test_validate_ray_version_compatibility_method(self, mocker):
10521080 """Test the _validate_ray_version_compatibility method directly."""
10531081 mocker .patch ("kubernetes.config.load_kube_config" )
10541082 mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1083+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
10551084 mock_api_instance = MagicMock ()
10561085 mock_api_class .return_value = mock_api_instance
10571086
@@ -1087,6 +1116,7 @@ def test_validate_cluster_config_image_method(self, mocker):
10871116 """Test the _validate_cluster_config_image method directly."""
10881117 mocker .patch ("kubernetes.config.load_kube_config" )
10891118 mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1119+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
10901120 mock_api_instance = MagicMock ()
10911121 mock_api_class .return_value = mock_api_instance
10921122
@@ -1122,6 +1152,7 @@ def test_validate_cluster_config_image_edge_cases(self, mocker):
11221152 """Test edge cases in _validate_cluster_config_image method."""
11231153 mocker .patch ("kubernetes.config.load_kube_config" )
11241154 mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1155+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
11251156 mock_api_instance = MagicMock ()
11261157 mock_api_class .return_value = mock_api_instance
11271158
0 commit comments