Sto cercando di utilizzare assert_called_once_with da unittest.finto https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.assert_called_once_with
Ma voglio controllare se 2 istanze di oggetti sono stati passati con te attributi corretti.
Così all'interno di una classe i overrided il __eq__
func:
def __eq__(self, other):
return (
self.id == other.id
and self.users == other.users
)
E il codice che ho usato come questa
mock_add_user.assert_called_once_with(context_fix, expected_user_obj1, expected_user_obj2, users)
Ma io continuo a ricevere un errore e che il teste tiene a confronto la repr dell'istanza, come questo
<app.domain.model.load_md.Load object at 0x10cb7d7d0>
E AssertionError: Expected call: add_user(<app.infrastructure.context.Context object at 0x10cb7da50>, <app.domain.model.load_md.Load object at 0x10cb7d7d0>, <app.domain.model.load_md.Load object at 0x10cb7d550>, [1, 2, 3, 2])
E Actual call: add_user(<app.infrastructure.context.Context object at 0x10cb7da50>, <app.domain.model.load_md.Load object at 0x10ca7f5d0>, <app.domain.model.load_md.Load object at 0x10cd1e650>, [1, 2, 3, 2])
Ho davvero bisogno di un modo per affermare se un'istanza di un oggetto viene passato come parametro della funzione con gli attributi corretti pieno.