title: Use python's mock patch to mock the value of parent class attribute(set by a calling an imported module) while testing a child class
body: <p>I'm trying to patch a function which I'm not directly importing but it is being used by the object under test.
  The patch is failing</p>
  
  <p>My hierarchy structure looks like this</p>
  
  <pre><code>--src
     |--a
     |  |--b 
     |     |-- parent.py
     |
     |--c
        |--d
           |--e
              |-child.py
  --test
     |--test_child.py
  </code></pre>
  
  <p>child.py looks like</p>
  
  <pre><code>class ChildClass(ParentClass):
  
      def child_method(self):
          // do stuff - which needs to be tested
          return self.parent_method()
  </code></pre>
  
  <p>parent.py looks like</p>
  
  <pre><code>from other_module import cool_function
  
  class ParentClass:
  
      attribute x = cool_function()
  
      def parent_method():
          print(x)
  </code></pre>
  
  <p>In my test I'm trying to test the child_method() of the ChildClass, with a mocked value of attribute X. For doing so I'm mocking the cool_function() which I imported. 
  I'm doing it like this </p>
  
  <p>test_child.py</p>
  
  <pre><code>from mock import patch
  from c.d.e.child import ChildClass
  
  @patch(a.b.c.cool_function) #Mocked cool_function()
  def test_child_function(mock_cool_function):
      mock_cool_function.return_value = Y # Mocked return value
      child_obj = ChildClass()
      child_obj.child_function()
      assert child_ojb.x == Y  # ===&gt; Fails. Returns value by executing cool_function()
      //other asserts 
  </code></pre>
  
  <p>Wanted to know what's going wrong here. I followed this guide - <a href="https://stackoverflow.com/questions/18191275/using-pythons-mock-patch-object-to-change-the-return-value-of-a-method-called-w">Using python&#39;s mock patch.object to change the return value of a method called within another method</a></p>