I was getting so frustrated.
I knew how to raise the exception with side_effect=. But, how do you mock the exception?
try: connection = connect_to_sqs except BotoServerError as m: if m.error_code == "AlreadyExistsException"
To get it to work, I inherited the exception class – BotoServerError
from boto.exceptions import BotoServerError class MockBotoServerError(BotoServerError): def __init__(self, error_code) self.error_code = error_code @mock.patch('cloudwhale.build.connect_to_sqs', side_effect=MockBotoServerError())
Order of decorator
Also, pay attention to the order of parameters. My assertions were failing left and right.
I’m Matt Chung. I’m a software engineer, seasoned technology leader, and father currently based in Seattle and London. I love to share what I know. I write about topic developing scalable & fail-safe software running in the AWS cloud, digital organization as a mechanism for unlocking your creativity, and maximizing our full potentials with personal development habits.View all articles