title: Trying to mock a dependency, but its initialization code still gets executed
body: <p>I am trying to mock a dependency in my unit test, but that dependency's initialization code still gets executed. Here is my code structure:</p>
  
  <pre><code>my_project
  |_src
  | |__dynamo_connector
  | |  |__dynamo_manager.py
  | |__package_to_test
  | |  |__process_message.py
  | |  |__process_message_test.py
  </code></pre>
  
  <p>The <code>dynamo_manager.py</code> file looks something like this:</p>
  
  <pre><code>import boto3
  import ...
  
  # This is the line causing the issue
  dynamodb_client = boto3.client("dynamodb")
  
  def add_item_to_dynamo(...):
  ...
  </code></pre>
  
  <p>The class that I want to test, <code>process_message.py</code>, looks something like this:</p>
  
  <pre><code>from my_project.src.dynamo_connector import add_item_to_dynamo
  import ...
  
  def method_to_test(...):
  ...
  </code></pre>
  
  <p>And this is what my test looks like:</p>
  
  <pre><code>import unittest
  from unittest import mock
  from unittest.mock import patch
  # The exception starts on this line
  from process_message import method_to_test
  
  class TestClass(unittest.TestCase):
      @patch('process_message.my_project.src.dynamo_connector'):
      def test_my_method(self, mocked_dynamo_connector):
          print("Hello, world")
  </code></pre>
  
  <p>My problem is that even though I mocked <code>dynamo_connector</code>, the <code>boto3.client("dynamodb")</code> line is still getting executed, which throws a botocore initialization exception. How do I properly mock the <code>dynamo_manager</code> class?</p>
  
  <p>I am using Python 3.6</p>