Python unittest - asserting dictionary with lists

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

    You might try PyHamcrest (Example corrected)

    assert_that(obj.exportToDict(), has_entries(
                                        { 'state': 2347,
                                          'neighbours': contains_inanyorder(1,2,3) }))
    

    (The first value 2347 actually gets wrapped in an implicit equal_to matcher.)

提交回复
热议问题