How to assert exception message in PyTest?
I kept forgetting how to assert exception messages in PyTest, so I finally checked the docs. Here’s a reference snippet.
import pytest
def broken() -> None:
raise ValueError("something went wrong")
def test_broken() -> None:
with pytest.raises(ValueError, match="went wrong"):
broken()
That’s it for today. Happy hacking! 🐍