diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index 4e10a3fbb..3ec9a365a 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -345,15 +345,13 @@ def _compare_eq_cls(left, right, verbose, type_fns): if same and verbose < 2: explanation.append(u"Omitting %s identical items, use -vv to show" % len(same)) elif same: - explanation += [u"Common attributes:"] + explanation += [u"Matching attributes:"] explanation += pprint.pformat(same).splitlines() if diff: - class_name = left.__class__.__name__ explanation += [u"Differing attributes:"] - for k in diff: + for field in diff: explanation += [ - (u"%s(%s=%r) != %s(%s=%r)") - % (class_name, k, getattr(left, k), class_name, k, getattr(right, k)) + (u"%s: %r != %r") % (field, getattr(left, field), getattr(right, field)) ] return explanation diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 2a55f70bc..bb54e394f 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -559,7 +559,7 @@ class TestAssert_reprcompare_dataclass(object): [ "*Omitting 1 identical items, use -vv to show*", "*Differing attributes:*", - "*SimpleDataObject(field_b='b') != SimpleDataObject(field_b='c')*", + "*field_b: 'b' != 'c'*", ] ) @@ -570,10 +570,10 @@ class TestAssert_reprcompare_dataclass(object): result.assert_outcomes(failed=1, passed=0) result.stdout.fnmatch_lines( [ - "*Common attributes:*", + "*Matching attributes:*", "*['field_a']*", "*Differing attributes:*", - "*SimpleDataObject(field_b='b') != SimpleDataObject(field_b='c')*", + "*field_b: 'b' != 'c'*", ] ) @@ -606,7 +606,7 @@ class TestAssert_reprcompare_attrsclass(object): lines = callequal(left, right) assert lines[1].startswith("Omitting 1 identical item") - assert "Common attributes" not in lines + assert "Matching attributes" not in lines for line in lines[1:]: assert "field_a" not in line @@ -620,7 +620,7 @@ class TestAssert_reprcompare_attrsclass(object): right = SimpleDataObject(1, "c") lines = callequal(left, right, verbose=2) - assert lines[1].startswith("Common attributes:") + assert lines[1].startswith("Matching attributes:") assert "Omitting" not in lines[1] assert lines[2] == "['field_a']" @@ -634,7 +634,7 @@ class TestAssert_reprcompare_attrsclass(object): right = SimpleDataObject(1, "b") lines = callequal(left, right, verbose=2) - assert lines[1].startswith("Common attributes:") + assert lines[1].startswith("Matching attributes:") assert "Omitting" not in lines[1] assert lines[2] == "['field_a']" for line in lines[2:]: