I would like to wrap an object generically enough to catch an exception on all methods.
Lets suppose I have this class:
class CanThrowException:
def not1(self, param):
if param == 1:
raise ValueError('Parameter value cannot be 1')
return "Your parameter is {}".format(param)
def not2(self, param):
if param == 2:
raise ValueError('Parameter value cannot be 2')
return "Your parameter is {}".format(param)
I would like to wrap the object to catch the exceptions, but without creating a class that defines all methods present in the CanThrowException class. Is there any way to do it in python?
I am using python bravado to parse a REST API definition and execute tests on the API. In normal use of an API, if an endpoint returns something different that http code 2xx, the call failed. That's why bravado will raise exceptions in those cases. But in my case I cause those errors while testing the API, so in that context they are not errors.
That's why I would like to isolate the use of bravado, managing the exception (as recommended by the bravado team) and returning what my tests need to know.
Thanks in advance!