title: Mocking, assert_called with, in python
body: <p>I need to make sure a function is being called with a specific argument in python. I have mocked this function out using magic mock.</p>
  
  <pre><code>self.function = MagicMock()
  self.function(subject= "Hello World")
  </code></pre>
  
  <p>Does something exist along the lines of </p>
  
  <pre><code>self.function.assert_called_with("Hello World")
  </code></pre>
  
  <p>or</p>
  
  <pre><code>self.function.assert_called_with(subject= "Hello World")
  </code></pre>
  
  <p>Sorry if this has been asked before, but I've been poking around the mock docs and it doesn't seem like any of the assert statements will work for me.</p>
  
  <p>EDIT: I added some debug output</p>
  
  <p>When I attempt to debug, I see</p>
  
  <pre><code>AssertionError: 
  Expected call: mock('Hello World')
  Actual call: mock('thing i dont care about', 'Hello World', 'thing i dont care about')
  </code></pre>
  
  <p>So apparently, the function is being called, but the assert is acting weird. It doesn't recognize "Hello World" in the list of arguments or something.</p>
  
  <p>EDIT2:</p>
  
  <p>I changed up my code a little bit, and it still isn't matching properly</p>
  
  <pre><code>self.function = MagicMock(field1 = None, field2 = None, subject = None, field4 = None)
  
  #later on...
  self.function(1,2,"Hello World",4)  #these params will not always be 1,2,4 .. I made them so to
                                       #show an example
  
  #even further down the road
  self.function.assert_called_with(ANY, ANY, "Hello World", ANY)
  </code></pre>
  
  <p>Something like this isn't working for me either. Still getting the error </p>
  
  <pre><code>AssertionError: 
  Expected call: mock(&lt;ANY&gt;, &lt;ANY&gt;, "Hello World", &lt;ANY&gt;)
  Actual call: mock(1,2,"Hello World", 4)
  </code></pre>
  
  <p>Again, I couldn't just do something like </p>
  
  <p>How does "ANY" correspond to pattern matching an argument?</p>