diff --git a/tests/test_field_for_schema.py b/tests/test_field_for_schema.py index 6a03cbb..6381051 100644 --- a/tests/test_field_for_schema.py +++ b/tests/test_field_for_schema.py @@ -55,31 +55,32 @@ def _assertAttrsEqual(self, a, b, msg=None): attrs_a = {attr for attr in vars(a) if not attr.startswith("_")} attrs_b = {attr for attr in vars(b) if not attr.startswith("_")} - if attrs_a - attrs_b: - self.fail( - f"Attributes in first value but not in second: {' '.join(map(repr, attrs_a - attrs_b))}" - ) - if attrs_b - attrs_a: - self.fail( - f"Attributes in second value but not in first: {' '.join(map(repr, attrs_b - attrs_a))}" - ) + if attrs_a != attrs_b: + if msg is None: + msg = "values do not have the same set of attributes" + self.fail(msg) + + checked = [] + + def assert_equal(v1, v2): + if (v1, v2) not in checked: + checked.append((v1, v2)) + if ( + type(v1) is type(v2) + and isinstance(v1, Sequence) + and isinstance(v1, Sequence) + and len(v1) == len(v1) + ): + # TestCase.assertSequenceEqual tests item equality with __eq__. + # (It doesn't dispatch to an assert* method based on the item type.) + # So we'll do the comparison ourself using assertEqual. + for left, right in zip(v1, v2): + assert_equal(left, right) + else: + self.assertEqual(v1, v2, msg) for attr in attrs_a | attrs_b: - value_a = a.__dict__[attr] - value_b = b.__dict__[attr] - if ( - type(value_a) is type(value_b) - and isinstance(value_a, Sequence) - and isinstance(value_b, Sequence) - and len(value_a) == len(value_b) - ): - # TestCase.assertSequenceEqual tests item equality with __eq__. - # (It doesn't dispatch to an assert* method based on the item type.) - # So we'll do the comparison ourself using assertEqual. - for v1, v2 in zip(value_a, value_b): - self.assertEqual(v1, v2, msg) - else: - self.assertEqual(value_a, value_b, msg) + assert_equal(vars(a)[attr], vars(b)[attr]) def test_int(self): self.assertFieldsEqual(