unit testing - When using python mox mock objects is there any way to avoid all of them being equal (as in __eq__)? -


I am facing some problems which are equal to all the counterfeit masks of any class, == , __ eq __ expressions though they are different objects (at least mock1 mock2 returns False ). Is there any way to stop that behavior?

In the example of the code given below, you can see that the count is wrong because it thinks that all socks are the same:

  import mox class MyClass (object): Passed real1 = MyClass () real2 = MyClass () listreal = (real1, real2) joke = mox.mox () mock1 = mocker.CreateMock (myClass) mock2 = mocker.CreateMock (MyClass) listmock = (mock1, mock2) real1 = = Real2 # false real1 is real2 # false listreal.count (real1) # 1 mock1 == mock2 # This is true mock1 is mock2 # false listmock.count (mock1) # 2    

After the

It seems that the implementation of __ eq __ for mox.mockAnything and mox.MockObject simply replay_mode and expected_calls_queue therefore compares any duplicate object that is expected of the same call is actually "equal" . MockAnything: Def __eq __ (self, RHS): "" "Provide custom arguments to compare objects." "Return (isinstance (RHS, MockAnything) and self _replay_mode == RHs._replay_mode and self._expected_calls_queue == rhs._expected_calls_queue)

Many additional implications when mocks for methods such as list.remove () , etc. That is used in

You have to add some calls to the fake method to make socks in the eyes of __ eq __ .

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -