ignoring an element from a dict when asserting in pytest
pytest, python
Solution
I solved this issue by creating object that equals to everything:
class EverythingEquals:
def __eq__(self, other):
return True
everything_equals = EverythingEquals()
def test_compare_dicts():
assert {'userName':'bob','lastModified':'2012-01-01'} == {'userName': 'bob', 'lastModified': everything_equals}
This way it will be compared as the same and also you will check that you have `'lastModified'` in your dict.
EDIT:
Now you can use `unittest.mock.ANY` instead of creating your own class.
Problem
I was wondering if there is a way to ignore an element in a dict when doing an assert in pytest. We have an assert which will compare a list containing a last_modified_date. The date will always be updated so there is no way to be sure that the date will be equal to the date originally entered. For example: ``` {'userName':'bob','lastModified':'2012-01-01'} ``` Thanks Jay