Last active
August 29, 2015 13:56
-
-
Save weissjeffm/8790010 to your computer and use it in GitHub Desktop.
error handling
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
import utils.error as error | |
# when we expect an error but don't get one, we get an error that tells us so | |
with error.expected_regex("foo"): | |
pass | |
Truncated Traceback (Use C-c C-x to view full TB): | |
/home/jweiss/workspace/cfme_tests/utils/error.py in expected(f) | |
62 try: | |
63 yield | |
---> 64 raise UnexpectedSuccessException("Expected error {} but got success instead.".format(f)) | |
65 except UnexpectedSuccessException: | |
66 raise | |
UnexpectedSuccessException: Expected error Regex "foo" but got success instead. | |
# When we expect a certain error but get a different one, the actual error bubbles up | |
with error.expected_regex("foo"): | |
raise Exception('bar!') | |
--------------------------------------------------------------------------- | |
Exception Traceback (most recent call last) | |
<ipython-input-9-aa3e96d2b9eb> in <module>() | |
2 reload(error) | |
3 with error.expected_regex("foo"): | |
----> 4 raise Exception('bar!') | |
5 | |
Exception: bar! | |
# when we get an error message that matches, handler exits normally | |
import utils.error as error | |
reload(error) | |
with error.expected_regex("foo"): | |
raise Exception('blah foo!') | |
None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment