Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always compare object mappings when ignore_eq is enabled. #137

Merged
merged 1 commit into from Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
19 changes: 19 additions & 0 deletions testfixtures/tests/test_compare.py
Expand Up @@ -1508,6 +1508,25 @@ 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

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