Python unittest - asserting dictionary with lists

后端 未结 4 849
挽巷
挽巷 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:46

    How about using all:

    assert all( (k,v) in resulting_dictionary.iteritems() 
                for (k,v) in obj.exportToDict().iteritems() )
    

    I use something like this with py.test, but I think it should work for you.


    A commenter pointed out that the order will screw me here---fair enough...I'd just use sets, then.

提交回复
热议问题