Skip to content

Commit

Permalink
Always compare object mappings when ignore_eq is enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlg committed Sep 4, 2020
1 parent 9684e98 commit 0ee19a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion testfixtures/comparison.py
Expand Up @@ -100,7 +100,7 @@ def compare_object(x, y, context, ignore_attributes=()):
y_attrs = _extract_attrs(y, _attrs_to_ignore(context, ignore_attributes, y))
if x_attrs is None or y_attrs is None or not (x_attrs and y_attrs):
return compare_simple(x, y, context)
if x_attrs != y_attrs:
if context.ignore_eq or x_attrs != y_attrs:
return _compare_mapping(x_attrs, y_attrs, context, x,
'attributes ', '.%s')

Expand Down
22 changes: 22 additions & 0 deletions testfixtures/tests/test_compare.py
Expand Up @@ -1508,6 +1508,28 @@ def test_django_orm_is_horrible_part_4(self):
ignore_eq=True
)

def test_nested_django_orm_in_object(self):
class MyObject(object):
def __init__(self, orm):
self.orm = orm

def __repr__(self):
return 'MyObject instance'

self.check_raises(
message="MyObject not as expected:\n"
"\n"
"attributes differ:\n"
"'orm': OrmObj: 1 (expected) != OrmObj: 2 (actual)\n"
"\n"
"While comparing .orm: OrmObj not as expected:\n"
"\n"
"attributes differ:\n"
"'a': 1 (expected) != 2 (actual)",
expected=MyObject(self.OrmObj(1)),
actual=MyObject(self.OrmObj(2)),
ignore_eq=True)

def test_mock_call_same(self):
m = Mock()
m.foo(1, 2, x=3)
Expand Down

0 comments on commit 0ee19a5

Please sign in to comment.