fix(tests): mock spacy in plugin tests to fix externally-managed-environment failures

This commit is contained in:
Artem Akymenko
2026-07-16 10:02:01 +03:00
parent 1268a83cff
commit ef07a8b5b2
2 changed files with 21 additions and 1 deletions
+18
View File
@@ -12,6 +12,7 @@ from __future__ import annotations
import logging
from pathlib import Path
from typing import Any
from unittest.mock import patch
import pytest
@@ -147,6 +148,23 @@ def engine_config() -> Any:
return EngineConfig(device="cpu")
@pytest.fixture(autouse=True)
def _mock_kokoro_pipeline():
"""Prevent real KPipeline initialization during generic plugin tests.
The real KPipeline requires spacy model downloads which aren't available
in externally-managed environments. Mock spacy's download and load so
the engine contract can be tested without heavy dependencies.
"""
from unittest.mock import MagicMock
mock_nlp = MagicMock()
with patch("spacy.cli.download"), \
patch("spacy.load", return_value=mock_nlp):
yield
@pytest.fixture
def create_engine(loaded_plugin, host_context, engine_config):
"""Create an engine instance from a loaded plugin.