mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-29 06:31:32 +00:00
test(tools): centralize disable_lazy_stt_install fixture in conftest
Move the autouse `_disable_lazy_stt_install` fixture out of the three transcription test files and into `tests/tools/conftest.py` as a regular (non-autouse) fixture. Each transcription test module opts in once at the top via `pytestmark = pytest.mark.usefixtures(...)`. Why: addresses three Copilot inline review comments on this PR that flagged the verbatim duplication across files. Centralizing also keeps the patch target in a single place, so a future rename of `_try_lazy_install_stt` only updates one location. Why opt-in (not autouse in conftest): other `tests/tools/` files do not patch `_HAS_FASTER_WHISPER` and have no reason to bypass the runtime lazy-install probe; making the fixture autouse globally would silently mask any future test that wants to exercise the real lazy-install path.
This commit is contained in:
parent
5dc232a6e2
commit
22b0d6dc1a
4 changed files with 28 additions and 42 deletions
|
|
@ -8,6 +8,8 @@ depend on the registry being populated should use it explicitly or via
|
||||||
``@pytest.mark.usefixtures("web_registry_populated")``.
|
``@pytest.mark.usefixtures("web_registry_populated")``.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -48,3 +50,20 @@ def web_registry_populated():
|
||||||
yield
|
yield
|
||||||
from agent.web_search_registry import _reset_for_tests
|
from agent.web_search_registry import _reset_for_tests
|
||||||
_reset_for_tests()
|
_reset_for_tests()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def disable_lazy_stt_install():
|
||||||
|
"""Disarm the runtime lazy-install probe so static ``_HAS_FASTER_WHISPER``
|
||||||
|
patches accurately simulate 'faster-whisper not installed'.
|
||||||
|
|
||||||
|
Without this, ``_try_lazy_install_stt()`` calls
|
||||||
|
``importlib.util.find_spec("faster_whisper")``, which returns truthy
|
||||||
|
whenever the package is installed in the dev / CI environment —
|
||||||
|
defeating the test's ``_HAS_FASTER_WHISPER=False`` patch.
|
||||||
|
|
||||||
|
Opt in at module scope with
|
||||||
|
``pytestmark = pytest.mark.usefixtures("disable_lazy_stt_install")``.
|
||||||
|
"""
|
||||||
|
with patch("tools.transcription_tools._try_lazy_install_stt", return_value=False):
|
||||||
|
yield
|
||||||
|
|
|
||||||
|
|
@ -23,25 +23,14 @@ def _fake_faster_whisper_module(mock_model):
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.usefixtures("disable_lazy_stt_install")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def _clear_openai_env(monkeypatch):
|
def _clear_openai_env(monkeypatch):
|
||||||
monkeypatch.delenv("OPENAI_API_KEY", raising=False)
|
monkeypatch.delenv("OPENAI_API_KEY", raising=False)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def _disable_lazy_stt_install():
|
|
||||||
"""Disarm the runtime lazy-install probe so static ``_HAS_FASTER_WHISPER``
|
|
||||||
patches accurately simulate 'faster-whisper not installed'.
|
|
||||||
|
|
||||||
Without this, ``_try_lazy_install_stt()`` calls
|
|
||||||
``importlib.util.find_spec("faster_whisper")``, which returns truthy
|
|
||||||
whenever the package is installed in the dev / CI environment —
|
|
||||||
defeating the test's ``_HAS_FASTER_WHISPER=False`` patch.
|
|
||||||
"""
|
|
||||||
with patch("tools.transcription_tools._try_lazy_install_stt", return_value=False):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
class TestGetProvider:
|
class TestGetProvider:
|
||||||
"""_get_provider() picks the right backend based on config + availability."""
|
"""_get_provider() picks the right backend based on config + availability."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@ from unittest.mock import MagicMock, patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.usefixtures("disable_lazy_stt_install")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def isolate_env(monkeypatch):
|
def isolate_env(monkeypatch):
|
||||||
"""Strip every STT-related env var so the test really exercises the
|
"""Strip every STT-related env var so the test really exercises the
|
||||||
|
|
@ -28,20 +31,6 @@ def isolate_env(monkeypatch):
|
||||||
monkeypatch.delenv(key, raising=False)
|
monkeypatch.delenv(key, raising=False)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def _disable_lazy_stt_install():
|
|
||||||
"""Disarm the runtime lazy-install probe so static ``_HAS_FASTER_WHISPER``
|
|
||||||
patches accurately simulate 'faster-whisper not installed'.
|
|
||||||
|
|
||||||
Without this, ``_try_lazy_install_stt()`` calls
|
|
||||||
``importlib.util.find_spec("faster_whisper")``, which returns truthy
|
|
||||||
whenever the package is installed in the dev / CI environment —
|
|
||||||
defeating the test's ``_HAS_FASTER_WHISPER=False`` patch.
|
|
||||||
"""
|
|
||||||
with patch("tools.transcription_tools._try_lazy_install_stt", return_value=False):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
class TestProviderSelectionGate:
|
class TestProviderSelectionGate:
|
||||||
"""``_get_provider`` picks the STT backend. If it only consulted
|
"""``_get_provider`` picks the STT backend. If it only consulted
|
||||||
``os.environ`` a user with keys in ``~/.hermes/.env`` would be told
|
``os.environ`` a user with keys in ``~/.hermes/.env`` would be told
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,9 @@ def sample_ogg(tmp_path):
|
||||||
return str(ogg_path)
|
return str(ogg_path)
|
||||||
|
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.usefixtures("disable_lazy_stt_install")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def clean_env(monkeypatch):
|
def clean_env(monkeypatch):
|
||||||
"""Ensure no real API keys leak into tests."""
|
"""Ensure no real API keys leak into tests."""
|
||||||
|
|
@ -53,20 +56,6 @@ def clean_env(monkeypatch):
|
||||||
monkeypatch.delenv("HERMES_LOCAL_STT_LANGUAGE", raising=False)
|
monkeypatch.delenv("HERMES_LOCAL_STT_LANGUAGE", raising=False)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def _disable_lazy_stt_install():
|
|
||||||
"""Disarm the runtime lazy-install probe so static ``_HAS_FASTER_WHISPER``
|
|
||||||
patches accurately simulate 'faster-whisper not installed'.
|
|
||||||
|
|
||||||
Without this, ``_try_lazy_install_stt()`` calls
|
|
||||||
``importlib.util.find_spec("faster_whisper")``, which returns truthy
|
|
||||||
whenever the package is installed in the dev / CI environment —
|
|
||||||
defeating the test's ``_HAS_FASTER_WHISPER=False`` patch.
|
|
||||||
"""
|
|
||||||
with patch("tools.transcription_tools._try_lazy_install_stt", return_value=False):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# _get_provider — full permutation matrix
|
# _get_provider — full permutation matrix
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue