diff --git a/tests/plugins/conftest.py b/tests/plugins/conftest.py index 5dc5ede..325b2ba 100644 --- a/tests/plugins/conftest.py +++ b/tests/plugins/conftest.py @@ -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. diff --git a/tests/test_kokoro_plugin.py b/tests/test_kokoro_plugin.py index f016388..fa86776 100644 --- a/tests/test_kokoro_plugin.py +++ b/tests/test_kokoro_plugin.py @@ -38,8 +38,10 @@ from tests.contracts.engine_contract import EngineContractMixin def _kokoro_available() -> bool: try: from kokoro import KPipeline # type: ignore[import-not-found] + import spacy + spacy.load("en_core_web_sm") return True - except ImportError: + except (ImportError, OSError): return False