Python unittest - asserting dictionary with lists

后端 未结 4 845
挽巷
挽巷 2021-02-19 08:22

While writing some tests for my class, I encountered interesting simple problem. I would like to assertDictEqual two dictionaries containing some list. But this lists may not be

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-19 08:35

    You can do:

    a = {i:sorted(j) if isinstance(j, list) else j for i,j in resulting_dictionary.iteritems()}
    b = {i:sorted(j) if isinstance(j, list) else j for i,j in obj.exportToDict().iteritems()}
    self.assertDictEqual(a, b)
    

提交回复
热议问题