Get rid of those tests; they are next to useless:
This tests if the Python implementation of
dict.__repr__
is working. Python itself already tests for this; focus on the project codebase instead. If Python fails to render a dictionary representation correctly it's not your project's job to fix that.Python dictionaries have no fixed ordering; testing if their representation matches a given string is not going to be stable.
Moreover, Python 3.3 introduces hash randomization, meaning that the order of a given dictionary will change from invocation to invocation. See
PYTHONHASHSEED
.
If you are testing the result of a project API calll, test for dictionary equality using self.assertEqual()
instead; it'll use assertDictEqual()
to give you meaningful error messages if the two dictionaries do not match.
Since Python 3.3 interprets u'foo'
as a literal for type str
, comparing output against {u'foo': u'bar}
will work across Python 2.6, 2.7 and 3.3 and newer.