mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
fix(tests): mock spacy in plugin tests to fix externally-managed-environment failures
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user