Last active
September 10, 2015 13:52
-
-
Save westphahl/5017083b165d10ad1827 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
class assert_raises(object): | |
def __init__(self, exc_type): | |
self.exc_type = exc_type | |
def __enter__(self): | |
pass | |
def __exit__(self, exc_type, exc_value, traceback): | |
assert self.exc_type == exc_type, "Expected exception not raised" | |
return True | |
# Usage | |
with assert_raises(Exception): | |
raise Exception("Error") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment