Skip to content

Commit

Permalink
Aid testing by not wrapping flexmock expectation exceptions
Browse files Browse the repository at this point in the history
Usually API methods will wrap any exceptions in OsbsException.
However, if the exception is e.g. a MethodCallError, perhaps because
a function expected never to be called has been called, this
may cause a test to pass and mask a bug.

Don't wrap MethodCallError or other flexmock expectation exceptions.

Signed-off-by: Tim Waugh <twaugh@redhat.com>
  • Loading branch information
twaugh committed Mar 4, 2017
1 parent bdf1c67 commit 74edf66
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions osbs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
from osbs.exceptions import OsbsException, OsbsValidationException, OsbsResponseException
# import utils in this way, so that we can mock standalone functions with flexmock
from osbs import utils
try:
from flexmock import MethodCallError, MethodSignatureError, CallOrderError
except ImportError:
class MethodCallError(Exception):
pass
class MethodSignatureError(Exception):
pass
class CallOrderError(Exception):
pass


# Decorator for API methods.
Expand All @@ -40,6 +49,9 @@ def catch_exceptions(*args, **kwargs):
except OsbsException:
# Re-raise OsbsExceptions
raise
except (MethodCallError, MethodSignatureError, CallOrderError):
# Aid debugging
raise
except Exception as ex:
# Convert anything else to OsbsException

Expand Down

0 comments on commit 74edf66

Please sign in to comment.