Example code: def createDict(key, value): return {key: value} if str(createDict("k", "v")) != "{'k': 'v'}": raise Exception("Dict wrong") The result is: {'key': 'v'} And it should be: {'k': 'v'}