[New-bugs-announce] [issue9131] test_set_reprs in test_pprint is fragile

Daniel Stutzbach report at bugs.python.org
Wed Jun 30 21:48:00 CEST 2010


New submission from Daniel Stutzbach <daniel at stutzbachenterprises.com>:

test_set_reprs in test_pprint creates a complex arrangement of frozensets and tests the pretty-printed repr against a string hard-coded in the test.  The hard-coded repr depends on the sort order of frozensets.  

However, "Since sets only define partial ordering (subset relationships), the output of the list.sort() method is undefined for lists of sets." (quoting http://docs.python.org/release/3.1/library/stdtypes.html#set-types-set-frozenset)

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.  Small changes to Python's sort algorithm cause the test to fail when it should pass.

I ran into this while playing with optimizations to the sort function, but I imagine other Python implementations will also run into trouble with this test.

----------
assignee: stutzbach
components: Tests
messages: 109008
nosy: stutzbach
priority: low
severity: normal
stage: needs patch
status: open
title: test_set_reprs in test_pprint is fragile
versions: Python 3.2, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9131>
_______________________________________


More information about the New-bugs-announce mailing list