55from vision_agents .plugins import funasr
66
77
8+ @pytest .fixture
9+ def stt_factory ():
10+ instances = []
11+
12+ def create_stt (* args , ** kwargs ):
13+ stt = funasr .STT (* args , ** kwargs )
14+ instances .append (stt )
15+ return stt
16+
17+ yield create_stt
18+
19+ for stt in instances :
20+ asyncio .run (stt .close ())
21+
22+
823class _FakeAutoModel :
924 pass
1025
@@ -56,17 +71,17 @@ def resample(self, sample_rate):
5671class TestSTT :
5772 """Unit tests for the FunASR STT plugin (no model loaded)."""
5873
59- def test_construct (self ):
74+ def test_construct (self , stt_factory ):
6075 """The plugin constructs and exposes the expected defaults without loading a model."""
61- stt = funasr . STT ()
76+ stt = stt_factory ()
6277 assert stt .provider_name == "funasr"
6378 assert stt .model_id == "iic/SenseVoiceSmall"
6479 assert stt .language == "auto"
6580 assert stt .device == "cpu"
6681 assert stt .use_itn is True
6782
68- def test_custom_params (self ):
69- stt = funasr . STT (
83+ def test_custom_params (self , stt_factory ):
84+ stt = stt_factory (
7085 model = "FunAudioLLM/Fun-ASR-Nano-2512" ,
7186 language = "zh" ,
7287 device = "cuda" ,
@@ -77,14 +92,14 @@ def test_custom_params(self):
7792 assert stt .device == "cuda"
7893 assert stt .use_itn is False
7994
80- def test_process_audio_raises_unexpected_buffer_errors (self ):
81- stt = funasr . STT (client = _FakeAutoModel ())
95+ def test_process_audio_raises_unexpected_buffer_errors (self , stt_factory ):
96+ stt = stt_factory (client = _FakeAutoModel ())
8297
8398 with pytest .raises (AssertionError , match = "unexpected audio bug" ):
8499 asyncio .run (stt .process_audio (_ExplodingPcmData (), participant = object ()))
85100
86- def test_process_buffer_raises_unexpected_transcription_errors (self ):
87- stt = funasr . STT (client = _ExplodingAutoModel ())
101+ def test_process_buffer_raises_unexpected_transcription_errors (self , stt_factory ):
102+ stt = stt_factory (client = _ExplodingAutoModel ())
88103 pcm_data = _FakePcmData (
89104 samples = _FakeSamples (size = 16000 ),
90105 duration_ms = 8000 ,
0 commit comments