-
-
Notifications
You must be signed in to change notification settings - Fork 246
Open
Labels
Description
Hi,
First of all, thanks for writing a great library. I have used it in a lot of testing and it saved me from so many bugs.
I just ran into a small oddity; it seems that when comparing Exception objects the 'message' attribute is not checked for differences. Consider this snippet:
>>> from deepdiff import DeepDiff
>>>
>>> e1 = KeyError()
>>> e2 = KeyError('foo')
>>> class ClassA(object):
... a = 1
... def __init__(self, b):
... self.b = b
...
>>> t1 = ClassA('')
>>> t2 = ClassA('foo')
>>> DeepDiff(e1, e2, verbose_level=2)
{}
>>> DeepDiff(t1, t2, verbose_level=2)
{'values_changed': {'root.b': {'new_value': 'foo', 'old_value': ''}}}
>>> e1.message
''
>>> e2.message
'foo'
>>> t1.b
''
>>> t2.b
'foo'
Tested with DeepDiff 3.3.0, same behavior on Python 2.7 and 3.6
I noticed this PR should theoretically have fixed this, as the message attribute is in fact returned by dir()
:
>>> {i: getattr(e1, i) for i in dir(e1) if not (i.startswith('__') and i.endswith('__'))}
{'message': '', 'args': ()}
>>> {i: getattr(e2, i) for i in dir(e2) if not (i.startswith('__') and i.endswith('__'))}
{'message': 'foo', 'args': ('foo',)}
But apparently it doesn't, so perhaps we don't get into __search_obj at all, or something's off in __search_dict... Debugging is fun, but don't have a lot of time for it now. Just posting the issue here and will check it later. :)
Cheers,
Mark
Activity
seperman commentedon Aug 2, 2018
Hi @Mark90
Happy to hear you like DeepDiff!
Thanks for bringing this up. I will investigate.
Sep
Mark90 commentedon Aug 4, 2018
Fix for this particular problem (based on dev/ branch) reusing the solution by Max Rothman in 54c7267:
Testcases in
tests/test_diff_text.py
to verifyBut there is one side-effect. The testcases making use of
test_diff_text.get_custom_objects_add_and_remove
reported it;Seeing as
get_custom_object_with_added_removed_methods()
does not add attributemethod_a
but changes its reference from the instance method to a different function, I'm inclined to think this is for the better. What do you think?