Skip to content

Instantly share code, notes, and snippets.

@westphahl
Last active September 10, 2015 13:52
Show Gist options
  • Save westphahl/5017083b165d10ad1827 to your computer and use it in GitHub Desktop.
Save westphahl/5017083b165d10ad1827 to your computer and use it in GitHub Desktop.
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