Unittest'ten assert_called_once_with kullanmaya çalışıyorum.alay https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.assert_called_once_with
Ancak, nesnelerin 2 örneğinin doğru özniteliklerle aktarılıp aktarılmadığını kontrol etmek istiyorum.
Bu yüzden sınıfın içinde geçersiz kıldım __eq__
işlev:
def __eq__(self, other):
return (
self.id == other.id
and self.users == other.users
)
Ve bu şekilde kullandığım kodda
mock_add_user.assert_called_once_with(context_fix, expected_user_obj1, expected_user_obj2, users)
Ama bir hata almaya devam ediyorum ve test, örneğin tekrarını karşılaştırmaya devam ediyor, bunun gibi
<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])
Gerçekten eğer bir nesne örneğini dolu özniteliklerini doğru ile fonksiyon bir parametre olarak geçirilen varsa savunmak için bir yola ihtiyacım var.