title: Return value not set as intended when mocking a method with @mock.patch.object
body: <p>My test should with reason succeed as I'm giving a return value with mocker.return_value,
  which should give customers a value so the function call ends up in the else statement &quot;Customer found&quot;.
  But it does not, from what I can tell the return value is not being mocked correctly, but why?</p>
  <p>Mock:</p>
  <pre><code>from datachecker import DataChecker
  from unittest import mock
  
  @mock.patch.object(DataChecker, &quot;execute_db&quot;)
  def test_find_customer_true(mocker):
      mocker.return_value = 1
      assert DataChecker.find_customer(mocker, 1) == True
  </code></pre>
  <p>Class:</p>
  <pre><code>import sqlite3
  from customer import Customer
  
  class DataChecker:
     def __init__(self):
          self.conn = sqlite3.connect('pos.db')
          self.cursor = self.conn.cursor()
  
      def find_customer(self, customerID):
          query = &quot;SELECT * FROM Customers WHERE ID == ?;&quot;
          customers = self.execute_db(query, customerID, True)
          print(customers)
          
          if len(customers) == 0:
              print(&quot;Customer with given ID not found in DB&quot;)
              return False
          else:
              print(&quot;Customer found&quot;)
              return True
  
      def execute_db(self, query, params=None, fetch_one=False):
          if params:
              self.cursor.execute(query, [params])
              self.conn.commit()
          else:
              self.cursor.execute(query)
              self.conn.commit()
          if fetch_one:
              return self.cursor.fetchone()
          else:
              return self.cursor.fetchall()
  </code></pre>
  <p>Error:</p>
  <pre><code>=============================================================================================== FAILURES ================================================================================================
  ________________________________________________________________________________________ test_find_customer_true ________________________________________________________________________________________
  
  mocker = &lt;MagicMock name='execute_db' id='139976570824072'&gt;
  
      @mock.patch.object(DataChecker, &quot;execute_db&quot;)
      def test_find_customer_true(mocker):
          mocker.return_value = &quot;hej&quot;
  &gt;       assert DataChecker.find_customer(mocker, 1) == True
  E    AssertionError: assert False == True
  E     +  where False = &lt;function DataChecker.find_customer at 0x7f4ed5e26598&gt;(&lt;MagicMock name='execute_db' id='139976570824072'&gt;, 1)
  E     +    where &lt;function DataChecker.find_customer at 0x7f4ed5e26598&gt; = DataChecker.find_customer
  
  ../lab2/tests/test_datachecker.py:45: AssertionError
  ----------------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------------
  &lt;MagicMock name='execute_db.execute_db()' id='139976570473832'&gt;
  Customer with given ID not found in DB
  ======================================================================================== short test summary info ========================================================================================
  FAILED tests/test_datachecker.py::test_find_customer_true - AssertionError: assert False == True
  </code></pre>
  <p>print(customers) gives:
  <code>&lt;MagicMock name='execute_db.execute_db()' id='139976570473832'&gt;</code></p>
  <p>To me it looks like there's something wrong here.. execute.db.execute_db().
  According to my logic this print should give: 1?</p>