Skip to content

Commit

Permalink
Avoid updating assertion message twice if already done
Browse files Browse the repository at this point in the history
  • Loading branch information
asfaltboy committed Aug 8, 2016
1 parent 0044e4e commit 2296697
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def assert_wrapper(__wrapped_mock_method__, *args, **kwargs):
except AssertionError as e:
__mock_self = args[0] # the mock instance
assert_call = mock_module.call(*args[1:], **kwargs)
if __mock_self.call_args is not None:
if __mock_self.call_args is not None and not hasattr(e, '_msg_updated'):
try:
if __wrapped_mock_method__.__name__ == 'assert_any_call':
assert assert_call in __mock_self.call_args_list
Expand All @@ -239,7 +239,9 @@ def assert_wrapper(__wrapped_mock_method__, *args, **kwargs):
except AssertionError as diff:
# raise a new detailed exception, appending to existing
msg = DETAILED_ASSERTION.format(original=e, detailed=diff)
raise AssertionError(msg.encode().decode('unicode_escape'))
err = AssertionError(msg.encode().decode('unicode_escape'))
err._msg_updated = True
raise err
raise e


Expand Down

0 comments on commit 2296697

Please sign in to comment.