检查使用运行时对象创建调用的模拟
Check mock called with runtime object create
我有类似 cassandra 集群的代码
cluster = Cluster(
config.CASS_CLUSTER,
load_balancing_policy=policies.DCAwareRoundRobinPolicy(
config.CASS_D_CENTER))
当我为此编写 UT 并尝试使用我的参数检查 Cluster
调用时。
mock_cluster.assert_called_with(
config.CASS_CLUSTER,
load_balancing_policy=policies.DCAwareRoundRobinPolicy(
config.CASS_D_CENTER))
报错。
AssertionError: Expected call: Cluster(['192.168.1.1'], load_balancing_policy=<cassandra.policies.DCAwareRoundRobinPolicy object at 0x106fa2ed0>)
Actual call: Cluster(['192.168.1.1'], load_balancing_policy=<cassandra.policies.DCAwareRoundRobinPolicy object at 0x106fa2cd0>)
我得到这个是因为两个对象不同,有什么方法可以在 mock 中检查 called_with
?
mock_cluster.assert_called_with(
config.CASS_CLUSTER,
load_balancing_policy=mock.ANY)
我有类似 cassandra 集群的代码
cluster = Cluster(
config.CASS_CLUSTER,
load_balancing_policy=policies.DCAwareRoundRobinPolicy(
config.CASS_D_CENTER))
当我为此编写 UT 并尝试使用我的参数检查 Cluster
调用时。
mock_cluster.assert_called_with(
config.CASS_CLUSTER,
load_balancing_policy=policies.DCAwareRoundRobinPolicy(
config.CASS_D_CENTER))
报错。
AssertionError: Expected call: Cluster(['192.168.1.1'], load_balancing_policy=<cassandra.policies.DCAwareRoundRobinPolicy object at 0x106fa2ed0>)
Actual call: Cluster(['192.168.1.1'], load_balancing_policy=<cassandra.policies.DCAwareRoundRobinPolicy object at 0x106fa2cd0>)
我得到这个是因为两个对象不同,有什么方法可以在 mock 中检查 called_with
?
mock_cluster.assert_called_with(
config.CASS_CLUSTER,
load_balancing_policy=mock.ANY)