Skip to content

Instantly share code, notes, and snippets.

@antonagestam
Last active May 6, 2019 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonagestam/5c99db6e750f99ce56132f6f56ee895d to your computer and use it in GitHub Desktop.
Save antonagestam/5c99db6e750f99ce56132f6f56ee895d to your computer and use it in GitHub Desktop.
from typing import Type, Iterator
import contextlib
@contextlib.contextmanager
def assert_raises(expected: Type[Exception]) -> Iterator:
try:
yield
except Exception as e:
assert isinstance(e, expected), (
f"Raised {type(e).__name__} instead of "
f"{expected.__name__}"
)
else:
raise AssertionError(
f"{expected.__name__} was not raised")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment