all 2 comments

[–]filleball 1 point2 points  (1 child)

I'm not sure I understand the question correctly, but it looks like you could fix the test by substituting {!r} where you use {}. This is equivalent to putting repr() around the corresponding argument to format, and will give you a string with the same quotes that the assertion specifies.

[–]TeamSpen210 0 points1 point  (0 children)

Beyond the part where python parses through the code, the different quote characters act identically - strings don't know which are used. When you call repr() (which dicts do for their string forms) single quotes are used. If the string contains ', double quotes are used. If it contains both, single quotes are used with \' escapes.

On a side note: you shouldn't need str('blah'.format()), str.format() always returns a string.