Last active
May 6, 2019 17:50
-
-
Save antonagestam/5c99db6e750f99ce56132f6f56ee895d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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