test_quiet_warnings.py
Language Python1.0 KB26 lines
"""pyannote's torchcodec warning is silenced, in the CLI and under pytest."""import warningsfrom transcription_pipeline.cli import QUIET# The shape pyannote emits: the message opens with a line break.MESSAGE = "\ntorchcodec is not installed correctly so built-in audio decoding will fail."def test_cli_filter_catches_the_real_message():with warnings.catch_warnings(record=True) as caught:warnings.simplefilter("always")for action, message in QUIET:warnings.filterwarnings(action, message=message)warnings.warn(MESSAGE, UserWarning)warnings.warn("something else", UserWarning)assert [str(w.message) for w in caught] == ["something else"]def test_pytest_config_catches_it_too():# No filters of our own here: only pyproject's filterwarnings is in force.with warnings.catch_warnings(record=True) as caught:warnings.warn(MESSAGE, UserWarning)warnings.warn("something else", UserWarning)assert [str(w.message) for w in caught] == ["something else"]