2

I have code for cassandra cluster like

cluster = Cluster(
        config.CASS_CLUSTER,
        load_balancing_policy=policies.DCAwareRoundRobinPolicy(
            config.CASS_D_CENTER))

When I write UT for this and try to check Cluster call with my parameter.

mock_cluster.assert_called_with(
    config.CASS_CLUSTER,
    load_balancing_policy=policies.DCAwareRoundRobinPolicy(
        config.CASS_D_CENTER))

It gives error.

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>)

I get this because both object are different, is there any way to check called_with in mock?

Nilesh
  • 20,521
  • 16
  • 92
  • 148

1 Answers1

1
mock_cluster.assert_called_with(
    config.CASS_CLUSTER,
    load_balancing_policy=mock.ANY)
Dan
  • 1,874
  • 1
  • 16
  • 21