How to assert a dict contains another dict without assertDictContainsSubset in python? [duplicate]

Although I’m using pytest, I found the following idea in a comment. It worked really great for me, so I thought it could be useful here.

Python 3:

assert dict1.items() <= dict2.items()

Python 2:

assert dict1.viewitems() <= dict2.viewitems()

It works with non-hashable items, but you can’t know exactly which item eventually fails.

Leave a Comment