<div dir="ltr">Hi,<div><br></div><div>I have been trying to do mocking with the letter number of mock objects possible and I recently found that I was having problems with mock object's methods.</div><div><br></div><div>
Lets say I patch a class such as this:</div><div><br></div><div>class MyC(object):</div><div> def my_func():</div><div><br></div><div>I use it in another class with an import like this:</div><div><br></div><div>from my import MyC</div>
<div><br></div><div>def func1():</div><div> myc = MyC()</div><div> myc.my_func('a','b')</div><div><br></div><div>And I put this in my tests:</div><div><br></div><div>@patch('code.MyC', spec=myc.MyC)</div>
<div>class TestMyC(TestCase):</div><div> def my_first_test(self, m_myc):</div><div> func1()</div><div> print m_myc.mock_calls</div><div> m_myc.assert_called_once_with()</div><div> m_myc.my_func.assert_called_once_with('a','b')</div>
<div><br></div><div>And the first assertion goes alright, but the second one doesn't. I thought it was due to creating an object from the class or something like that, but the print statement outputs:</div><div>[call(), call().my_func(u'a', u'b')]</div>
<div><br></div><div>Which is correct. Any idea on this?</div><div><br></div><div><div><div dir="ltr">Javier Domingo Cansino<br>Research & Development Junior Engineer<br>Fon Labs Workgroup, Getxo - Spain.</div></div>
</div></div>