Created
April 4, 2012 23:37
-
-
Save zmsmith/2306590 to your computer and use it in GitHub Desktop.
Method for creating a Mock side_effect that only raises an exception for n calls
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
def get_exception_side_effect(num_of_exceptions, exception_class=Exception): | |
def side_effect(*args, **kwargs): | |
side_effect.calls += 1 | |
if side_effect.calls > num_of_exceptions: | |
return Mock() | |
else: | |
raise exception_class | |
side_effect.calls = 0 | |
return side_effect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment