So I have a to string method in one of my classes:
def __str__(self):
# some irrelevant code
raise KeyError("aaa")
Then in my tests I do:
with self.assertRaises(KeyError) as cm:
str(myobject)
self.assertEquals("%s" % cm.exception, "aaa")
I get this output:
self.assertEquals("%s" % cm.exception, "aaa")
AssertionError: "'aaa'" != 'aaa'
Any ideas what could be causing this?
When formatting a
KeyErroras a string, the representation of the offending key is included:The representation of a string includes the surrounding single quotes, so you should use
or the more straight-foward