title: Test function with lru_cache decorator
body: <p>I'm attempting to test a a method that is memoized through <code>lru_cache</code> (since it's an expensive database call). with <code>pytest-mock</code>.</p>
  
  <p>A simplified version of the code is:</p>
  
  <pre><code>class User:
  
      def __init__(self, file):
          # load a file
  
      @lru_cache
      def get(self, user_id):
          # do expensive call
  </code></pre>
  
  <p>Then I'm testing:</p>
  
  <pre><code>class TestUser:
  
      def test_get_is_called(self, mocker):
          data = mocker.ANY
          user = User(data)
          repository.get(user_id)
          open_mock = mocker.patch('builtins.open', mocker.mock_open())
          open_mock.assert_called_with('/foo')
  
  </code></pre>
  
  <p>But I'm getting the following error:</p>
  
  <pre><code>TypeError: unhashable type: '_ANY'
  </code></pre>
  
  <p>This happens because <code>functools.lru_cache</code> needs the keys stored to be <em>hashable</em> i.e. have a method <code>__hash__</code> or <code>__cmp__</code> implemented.</p>
  
  <p>How can I mock such methods in a mocker to make it work?</p>
  
  <p>I've tried</p>
  
  <pre><code>user.__hash__.return_value = 'foo'
  </code></pre>
  
  <p>with no luck.</p>