我试图使用assert_called_once_with从单元测试.模拟 https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.assert_called_once_with
但我想检查,如果2个实例的对象已经通过与te正确的属性。
所以内部流我重写的 __eq__
func:
def __eq__(self, other):
return (
self.id == other.id
and self.users == other.users
)
在代码我曾像这样
mock_add_user.assert_called_once_with(context_fix, expected_user_obj1, expected_user_obj2, users)
但是我继续收到错误和睾丸,保持比较repr的实例,这样的
<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])
我真的需要一种可以断言,如果一个实例的对象已被通过作为一个参数的功能的正确性填补。