<p dir="ltr">I think the call() objects you create for the expected and the ones used in the repr of the actuals it's being compared with arent actually the same type of thing.</p>
<p dir="ltr">Try a print(type(call())) and a print(type(c) for c in MockFoo.method_calls)?<br><br></p>
<br><div class="gmail_quote"><div dir="ltr">On Tue, 14 Feb 2017, 18:00 John W, <<a href="mailto:jwdevel@gmail.com">jwdevel@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I encountered my problem in Python3.4's unittest.mock, but I imagine<br class="gmail_msg">
people on this list might be able to help (is there a better place?).<br class="gmail_msg">
<br class="gmail_msg">
I made a SO post about this, too, but haven't seen much movement<br class="gmail_msg">
there: <a href="http://stackoverflow.com/questions/42212433/what-is-wrong-with-this-simple-unittest-mock-use-case" rel="noreferrer" class="gmail_msg" target="_blank">http://stackoverflow.com/questions/42212433/what-is-wrong-with-this-simple-unittest-mock-use-case</a><br class="gmail_msg">
<br class="gmail_msg">
Basically, `assert_has_calls` seems to be behaving in a strange way,<br class="gmail_msg">
or else I am misunderstanding something - which is entirely possible,<br class="gmail_msg">
as I'm new to unittest.mock.<br class="gmail_msg">
<br class="gmail_msg">
I have some fairly small code that repro's the issue:<br class="gmail_msg">
<br class="gmail_msg">
$ cat test.py<br class="gmail_msg">
from unittest.mock import patch, call<br class="gmail_msg">
<br class="gmail_msg">
class Foo:<br class="gmail_msg">
def __init__(self):<br class="gmail_msg">
pass<br class="gmail_msg">
def my_method(self, value):<br class="gmail_msg">
pass<br class="gmail_msg">
<br class="gmail_msg">
def test_foo():<br class="gmail_msg">
with patch('test.Foo', autospec=True) as MockFoo:<br class="gmail_msg">
# Note: in the real code, this usage of Foo is off in some<br class="gmail_msg">
other module.<br class="gmail_msg">
# Just putting it here for compactness.<br class="gmail_msg">
m = Foo()<br class="gmail_msg">
m.my_method(123)<br class="gmail_msg">
MockFoo.assert_has_calls([call(), call().my_method(123)])<br class="gmail_msg">
<br class="gmail_msg">
$ py.test test.py<br class="gmail_msg">
... <snip long output> ...<br class="gmail_msg">
E AssertionError: Calls not found.<br class="gmail_msg">
E Expected: [call(), call().my_method(123)]<br class="gmail_msg">
E Actual: [call(), call().my_method(123)]<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
The list of calls seems to match exactly, yet the assert fails.<br class="gmail_msg">
What's going on, here?<br class="gmail_msg">
<br class="gmail_msg">
Oddly, if I remove the 'value' parameter of my_method (and the<br class="gmail_msg">
corresponding 123 inputs), it works fine.<br class="gmail_msg">
<br class="gmail_msg">
Also, if I do it this way instead, everything works:<br class="gmail_msg">
<br class="gmail_msg">
MockFoo.assert_has_calls([call()])<br class="gmail_msg">
r = MockFoo.return_value<br class="gmail_msg">
r.assert_has_calls([call.my_method(123)])<br class="gmail_msg">
<br class="gmail_msg">
That makes sense to me, but I don't understand why it would be<br class="gmail_msg">
different from the original case.<br class="gmail_msg">
<br class="gmail_msg">
... Help?<br class="gmail_msg">
<br class="gmail_msg">
Thanks<br class="gmail_msg">
-John<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
testing-in-python mailing list<br class="gmail_msg">
<a href="mailto:testing-in-python@lists.idyll.org" class="gmail_msg" target="_blank">testing-in-python@lists.idyll.org</a><br class="gmail_msg">
<a href="http://lists.idyll.org/listinfo/testing-in-python" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br class="gmail_msg">
</blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><p dir="ltr">--<br>
Harry Percival<br>
+44 78877 02511</p>
</div>