From 22b0d6dc1aa53bc37e2883feb736e62e536e13e2 Mon Sep 17 00:00:00 2001 From: briandevans <252620095+briandevans@users.noreply.github.com> Date: Fri, 22 May 2026 03:11:55 -0700 Subject: [PATCH] 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. --- tests/tools/conftest.py | 19 +++++++++++++++++++ tests/tools/test_transcription.py | 17 +++-------------- .../test_transcription_dotenv_fallback.py | 17 +++-------------- tests/tools/test_transcription_tools.py | 17 +++-------------- 4 files changed, 28 insertions(+), 42 deletions(-) diff --git a/tests/tools/conftest.py b/tests/tools/conftest.py index 548b37f38c9..494dd206a1e 100644 --- a/tests/tools/conftest.py +++ b/tests/tools/conftest.py @@ -8,6 +8,8 @@ depend on the registry being populated should use it explicitly or via ``@pytest.mark.usefixtures("web_registry_populated")``. """ +from unittest.mock import patch + import pytest @@ -48,3 +50,20 @@ def web_registry_populated(): yield from agent.web_search_registry import _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 diff --git a/tests/tools/test_transcription.py b/tests/tools/test_transcription.py index 606a3e100a2..b7e399ca426 100644 --- a/tests/tools/test_transcription.py +++ b/tests/tools/test_transcription.py @@ -23,25 +23,14 @@ def _fake_faster_whisper_module(mock_model): # --------------------------------------------------------------------------- +pytestmark = pytest.mark.usefixtures("disable_lazy_stt_install") + + @pytest.fixture(autouse=True) def _clear_openai_env(monkeypatch): 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: """_get_provider() picks the right backend based on config + availability.""" diff --git a/tests/tools/test_transcription_dotenv_fallback.py b/tests/tools/test_transcription_dotenv_fallback.py index 6248d0acd06..5a0517c3bee 100644 --- a/tests/tools/test_transcription_dotenv_fallback.py +++ b/tests/tools/test_transcription_dotenv_fallback.py @@ -12,6 +12,9 @@ from unittest.mock import MagicMock, patch import pytest +pytestmark = pytest.mark.usefixtures("disable_lazy_stt_install") + + @pytest.fixture(autouse=True) def isolate_env(monkeypatch): """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) -@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: """``_get_provider`` picks the STT backend. If it only consulted ``os.environ`` a user with keys in ``~/.hermes/.env`` would be told diff --git a/tests/tools/test_transcription_tools.py b/tests/tools/test_transcription_tools.py index 953a68be79e..c7cf8950239 100644 --- a/tests/tools/test_transcription_tools.py +++ b/tests/tools/test_transcription_tools.py @@ -42,6 +42,9 @@ def sample_ogg(tmp_path): return str(ogg_path) +pytestmark = pytest.mark.usefixtures("disable_lazy_stt_install") + + @pytest.fixture(autouse=True) def clean_env(monkeypatch): """Ensure no real API keys leak into tests.""" @@ -53,20 +56,6 @@ def clean_env(monkeypatch): 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 # ============================================================================