diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index ad3a193..aa66376 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -203,7 +203,29 @@ class QueryTestCase(unittest.TestCase): others.should.not.be: like.this}""" self.assertEqual(DottedPrettyPrinter().pformat(o), exp) + @support.cpython_only def test_set_reprs(self): + # This test creates a complex arrangement of frozensets and + # compares the pretty-printed repr against a string hard-coded in + # the test. The hard-coded repr depends on the sort order of + # frozensets. + # + # However, as the docs point out: "Since sets only define + # partial ordering (subset relationships), the output of the + # list.sort() method is undefined for lists of sets." + # + # In a nutshell, the test assumes frozenset({0}) will always + # sort before frozenset({1}), but: + # + # >>> frozenset({0}) < frozenset({1}) + # False + # >>> frozenset({1}) < frozenset({0}) + # False + # + # Consequently, this test is fragile and + # implementation-dependent. Small changes to Python's sort + # algorithm cause the test to fail when it should pass. + self.assertEqual(pprint.pformat(set()), 'set()') self.assertEqual(pprint.pformat(set(range(3))), '{0, 1, 2}') self.assertEqual(pprint.pformat(frozenset()), 'frozenset()')