title: unittest.mock.ANY won't match MagicMock
body: <p>I have a few unit tests that cover a wrapper class around my database using sqlalchemy:</p>
  
  <pre><code>exe_mock = self.database.connection.execute
  self.database.select()
  exe_mock.assert_called_once_with(ANY)
  self.assertIn("name='table.select().where()'", repr(exe_mock.call_args[0][0]))
  </code></pre>
  
  <p>I run the test locally, everything works fine. But Jenkins runs the same test and this happens:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/var/lib/jenkins/workspace/project-develop/tests/test_persistence.py", line 37, in test_select
      exe_mock.assert_called_once_with(ANY)
    File "/usr/lib64/python3.5/unittest/mock.py", line 803, in assert_called_once_with
      return self.assert_called_with(*args, **kwargs)
    File "/usr/lib64/python3.5/unittest/mock.py", line 792, in assert_called_with
      raise AssertionError(_error_message()) from cause
  AssertionError: Expected call: execute(&lt;ANY&gt;)
  Actual call: execute(&lt;MagicMock name='table.select().where()' id='140334112380240'&gt;)
  </code></pre>
  
  <p>Now, this is very awkward. Why wouldn't <code>ANY</code> be able to match with <code>MagicMock</code>?</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>After remotely connecting to the Jenkins worker, I activated the virtualenv por that project and reproduced the error:</p>
  
  <pre><code>&gt;&gt;&gt; from unittest.mock import MagicMock, ANY
  &gt;&gt;&gt; f = MagicMock()
  &gt;&gt;&gt; f(MagicMock())
  &lt;MagicMock name='mock()' id='139946030261304'&gt;
  &gt;&gt;&gt; f.called
  True
  &gt;&gt;&gt; 
  &gt;&gt;&gt; f.assert_called_once_with(ANY)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/lib64/python3.5/unittest/mock.py", line 803, in assert_called_once_with
      return self.assert_called_with(*args, **kwargs)
    File "/usr/lib64/python3.5/unittest/mock.py", line 792, in assert_called_with
      raise AssertionError(_error_message()) from cause
  AssertionError: Expected call: mock(&lt;ANY&gt;)
  Actual call: mock(&lt;MagicMock id='139946030228088'&gt;)
  </code></pre>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Turns out the problem is not localized in the virtualenv, it is in the python installation. </p>
  
  <p>Running <code>python34 -c "from unittest.mock import MagicMock, ANY; f = MagicMock(); f(MagicMock()); f.assert_called_once_with(ANY);"</code> will work gracefully.</p>
  
  <p>Running <code>python35 -c "from unittest.mock import MagicMock, ANY; f = MagicMock(); f(MagicMock()); f.assert_called_once_with(ANY);"</code> will raise the exception.</p>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>Using <code>pdb</code>, I could see that the failing point is <code>((ANY,), {}) != call(MagicMock())</code> that should return <code>False</code> but is returning <code>True</code>.</p>
  
  <p>Weirdly enough, <code>((ANY,), {}) == call(MagicMock())</code> also returns <code>True</code>.</p>
  
  <p>Remotely: </p>
  
  <pre><code>&gt;&gt;&gt; pdb.run('((ANY,), {}) != c')
  &gt; &lt;string&gt;(1)&lt;module&gt;()-&gt;None
  (Pdb) s
  --Return--
  &gt; &lt;string&gt;(1)&lt;module&gt;()-&gt;None
  </code></pre>
  
  <p>Locally:</p>
  
  <pre><code>&gt;&gt;&gt; pdb.run('((ANY,), {}) != c')
  &gt; &lt;string&gt;(1)&lt;module&gt;()-&gt;None
  (Pdb) s
  --Call--
  &gt; /usr/lib/python3.5/unittest/mock.py(1981)__eq__()
  -&gt; def __eq__(self, other):
  </code></pre>