mattrguerra/transcription-pipelinemainPrivate on GitHub, published here in full

test_quiet_warnings.py

Language Python1.0 KB26 lines

tests/test_quiet_warnings.py

  1. """pyannote's torchcodec warning is silenced, in the CLI and under pytest."""
  2. import warnings
  3. from transcription_pipeline.cli import QUIET
  4. # The shape pyannote emits: the message opens with a line break.
  5. MESSAGE = "\ntorchcodec is not installed correctly so built-in audio decoding will fail."
  6. def test_cli_filter_catches_the_real_message():
  7. with warnings.catch_warnings(record=True) as caught:
  8. warnings.simplefilter("always")
  9. for action, message in QUIET:
  10. warnings.filterwarnings(action, message=message)
  11. warnings.warn(MESSAGE, UserWarning)
  12. warnings.warn("something else", UserWarning)
  13. assert [str(w.message) for w in caught] == ["something else"]
  14. def test_pytest_config_catches_it_too():
  15. # No filters of our own here: only pyproject's filterwarnings is in force.
  16. with warnings.catch_warnings(record=True) as caught:
  17. warnings.warn(MESSAGE, UserWarning)
  18. warnings.warn("something else", UserWarning)
  19. assert [str(w.message) for w in caught] == ["something else"]