Skip to content

Commit 4da6ce8

Browse files
committed
Make parity-failure output more obvious
Print each offender on its own line, labelled with which side is missing the counterpart, instead of dumping two summary sentences with embedded list reprs. Factor the duplicated set-comprehension into a small inner helper so the assertion body is also a touch shorter. Sample failure (deleting one mirrored test, adding two extras): TestPEP828Operation is not a 1:1 mirror of TestPEP380Operation (suffix '_ayf'): missing in TestPEP828Operation: test_yield_from_empty_ayf no counterpart in TestPEP380Operation: test_made_up_extra_ayf no counterpart in TestPEP380Operation: test_other_extra_ayf
1 parent e95df7d commit 4da6ce8

1 file changed

Lines changed: 18 additions & 23 deletions

File tree

Lib/test/test_async_yield_from.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,29 +1630,24 @@ def assert_parity(self, base_class, variant_class, *, suffix):
16301630
``test_xxx<suffix>`` on ``variant_class`` and vice versa. Variant-only
16311631
tests belong in a separate TestCase class.
16321632
"""
1633-
base_tests = {
1634-
n for n in dir(base_class)
1635-
if n.startswith("test_") and callable(getattr(base_class, n))
1636-
}
1637-
variant_tests = {
1638-
n for n in dir(variant_class)
1639-
if n.startswith("test_") and callable(getattr(variant_class, n))
1640-
}
1641-
expected = {n + suffix for n in base_tests}
1642-
missing = sorted(expected - variant_tests)
1643-
extra = sorted(variant_tests - expected)
1644-
problems = []
1645-
if missing:
1646-
problems.append(
1647-
f"{variant_class.__name__} missing variants of "
1648-
f"{base_class.__name__} tests (suffix {suffix!r}): {missing}"
1649-
)
1650-
if extra:
1651-
problems.append(
1652-
f"{variant_class.__name__} has tests with no counterpart in "
1653-
f"{base_class.__name__} (suffix {suffix!r}): {extra}"
1654-
)
1655-
self.assertEqual(problems, [], "\n".join(problems))
1633+
def test_methods(cls):
1634+
return {n for n in dir(cls)
1635+
if n.startswith("test_") and callable(getattr(cls, n))}
1636+
1637+
expected = {n + suffix for n in test_methods(base_class)}
1638+
actual = test_methods(variant_class)
1639+
missing = sorted(expected - actual)
1640+
extra = sorted(actual - expected)
1641+
if missing or extra:
1642+
lines = [
1643+
f"{variant_class.__name__} is not a 1:1 mirror of "
1644+
f"{base_class.__name__} (suffix {suffix!r}):"
1645+
]
1646+
for name in missing:
1647+
lines.append(f" missing in {variant_class.__name__}: {name}")
1648+
for name in extra:
1649+
lines.append(f" no counterpart in {base_class.__name__}: {name}")
1650+
self.fail("\n".join(lines))
16561651

16571652
def test_TestPEP828Operation(self):
16581653
self.assert_parity(

0 commit comments

Comments
 (0)