test_exception_custom_html.py 530 B

1234567891011121314151617181920212223
  1. from __future__ import annotations
  2. import pytest
  3. from markupsafe import escape
  4. class CustomHtmlThatRaises:
  5. def __html__(self) -> str:
  6. raise ValueError(123)
  7. def test_exception_custom_html() -> None:
  8. """Checks whether exceptions in custom __html__ implementations are
  9. propagated correctly.
  10. There was a bug in the native implementation at some point:
  11. https://github.com/pallets/markupsafe/issues/108
  12. """
  13. obj = CustomHtmlThatRaises()
  14. with pytest.raises(ValueError):
  15. escape(obj)