Skip to content

Commit 4de5be5

Browse files
committed
Patch pipeline factory in test setup and teardown
Replaces direct assignment of the pipeline factory in tearDown with a patch in setUp and proper cleanup in tearDown. This ensures test isolation and avoids interference between tests by consistently patching and unpatching the factory.
1 parent 3ff1d94 commit 4de5be5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

ansible_ai_connect/main/tests/test_utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# )
2424
# from ansible_ai_connect.test_utils import WisdomServiceLogAwareTestCase
2525

26+
from unittest.mock import patch
27+
2628
from django.apps import apps
2729
from django.test import override_settings
2830

@@ -34,10 +36,16 @@
3436

3537
@override_settings(ANSIBLE_AI_MODEL_MESH_CONFIG=mock_config("wca"))
3638
class TestHasWCAProvidersWithWCAProvider(WisdomServiceLogAwareTestCase):
39+
def setUp(self):
40+
super().setUp()
41+
# Patch the pipeline factory to avoid test interference
42+
self.pipeline_factory_patcher = patch.object(
43+
apps.get_app_config("ai"), "_pipeline_factory", ModelPipelineFactory()
44+
)
45+
self.pipeline_factory_patcher.start()
46+
3747
def tearDown(self):
38-
"""Reset pipeline factory to avoid test interference."""
39-
# Force recreation of the factory with current configuration
40-
apps.get_app_config("ai")._pipeline_factory = ModelPipelineFactory()
48+
self.pipeline_factory_patcher.stop()
4149
super().tearDown()
4250

4351
def test_returns_true_with_wca_provider(self):

0 commit comments

Comments
 (0)